diff -r 4eee3d738d81 Modules/posixmodule.c --- a/Modules/posixmodule.c Mon Jun 13 16:10:32 2011 -0500 +++ b/Modules/posixmodule.c Tue Jun 14 11:39:49 2011 +0900 @@ -1094,6 +1094,11 @@ int buf_size, result_length; wchar_t *buf; + if(!check_GetFinalPathNameByHandle()) { + SetLastError(ERROR_NOT_SUPPORTED); + return FALSE; + } + /* We have a good handle to the target, use it to determine the target path name (then we'll call lstat on it). */ buf_size = Py_GetFinalPathNameByHandleW(hdl, 0, 0, @@ -1102,6 +1107,11 @@ return FALSE; buf = (wchar_t *)malloc((buf_size+1)*sizeof(wchar_t)); + if (!buf) { + SetLastError(ERROR_OUTOFMEMORY); + return FALSE; + } + result_length = Py_GetFinalPathNameByHandleW(hdl, buf, buf_size, VOLUME_NAME_DOS); @@ -1135,14 +1145,6 @@ wchar_t *target_path; const char *dot; - if(!check_GetFinalPathNameByHandle()) { - /* If the OS doesn't have GetFinalPathNameByHandle, return a - NotImplementedError. */ - PyErr_SetString(PyExc_NotImplementedError, - "GetFinalPathNameByHandle not available on this platform"); - return -1; - } - hFile = CreateFileA( path, FILE_READ_ATTRIBUTES, /* desired access */ @@ -1189,7 +1191,7 @@ if (!CloseHandle(hFile)) return -1; - if (traverse) { + if (traverse && reparse_tag == IO_REPARSE_TAG_SYMLINK) { /* In order to call GetFinalPathNameByHandle we need to open the file without the reparse handling flag set. */ hFile2 = CreateFileA( @@ -1233,14 +1235,6 @@ wchar_t *target_path; const wchar_t *dot; - if(!check_GetFinalPathNameByHandle()) { - /* If the OS doesn't have GetFinalPathNameByHandle, return a - NotImplementedError. */ - PyErr_SetString(PyExc_NotImplementedError, - "GetFinalPathNameByHandle not available on this platform"); - return -1; - } - hFile = CreateFileW( path, FILE_READ_ATTRIBUTES, /* desired access */ @@ -1287,7 +1281,7 @@ if (!CloseHandle(hFile)) return -1; - if (traverse) { + if (traverse && reparse_tag == IO_REPARSE_TAG_SYMLINK) { /* In order to call GetFinalPathNameByHandle we need to open the file without the reparse handling flag set. */ hFile2 = CreateFileW(