94 lines
3.3 KiB
Diff
94 lines
3.3 KiB
Diff
diff -Naur Python-3.6.5-orig/Modules/posixmodule.c Python-3.6.5/Modules/posixmodule.c
|
|
--- Python-3.6.5-orig/Modules/posixmodule.c 2018-04-16 09:54:09.427899000 +0300
|
|
+++ Python-3.6.5/Modules/posixmodule.c 2018-04-16 09:54:59.098180600 +0300
|
|
@@ -1511,6 +1511,31 @@
|
|
return TRUE;
|
|
}
|
|
|
|
+/* Grab GetFinalPathNameByHandle dynamically from kernel32 */
|
|
+static int has_GetFinalPathNameByHandle = -1;
|
|
+static DWORD (CALLBACK *Py_GetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD,
|
|
+ DWORD);
|
|
+static int
|
|
+check_GetFinalPathNameByHandle()
|
|
+{
|
|
+ HINSTANCE hKernel32;
|
|
+ DWORD (CALLBACK *Py_GetFinalPathNameByHandleA)(HANDLE, LPSTR, DWORD,
|
|
+ DWORD);
|
|
+
|
|
+ /* only recheck */
|
|
+ if (-1 == has_GetFinalPathNameByHandle)
|
|
+ {
|
|
+ hKernel32 = GetModuleHandleW(L"KERNEL32");
|
|
+ *(FARPROC*)&Py_GetFinalPathNameByHandleA = GetProcAddress(hKernel32,
|
|
+ "GetFinalPathNameByHandleA");
|
|
+ *(FARPROC*)&Py_GetFinalPathNameByHandleW = GetProcAddress(hKernel32,
|
|
+ "GetFinalPathNameByHandleW");
|
|
+ has_GetFinalPathNameByHandle = Py_GetFinalPathNameByHandleA &&
|
|
+ Py_GetFinalPathNameByHandleW;
|
|
+ }
|
|
+ return has_GetFinalPathNameByHandle;
|
|
+}
|
|
+
|
|
static BOOL
|
|
get_target_path(HANDLE hdl, wchar_t **target_path)
|
|
{
|
|
@@ -1519,8 +1544,8 @@
|
|
|
|
/* 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 = GetFinalPathNameByHandleW(hdl, 0, 0,
|
|
- VOLUME_NAME_DOS);
|
|
+ buf_size = Py_GetFinalPathNameByHandleW(hdl, 0, 0,
|
|
+ VOLUME_NAME_DOS);
|
|
if(!buf_size)
|
|
return FALSE;
|
|
|
|
@@ -1530,7 +1555,7 @@
|
|
return FALSE;
|
|
}
|
|
|
|
- result_length = GetFinalPathNameByHandleW(hdl,
|
|
+ result_length = Py_GetFinalPathNameByHandleW(hdl,
|
|
buf, buf_size, VOLUME_NAME_DOS);
|
|
|
|
if(!result_length) {
|
|
@@ -1560,6 +1585,12 @@
|
|
wchar_t *target_path;
|
|
const wchar_t *dot;
|
|
|
|
+ if(!check_GetFinalPathNameByHandle()) {
|
|
+ /* If the OS doesn't have GetFinalPathNameByHandle, don't
|
|
+ traverse reparse point. */
|
|
+ traverse = FALSE;
|
|
+ }
|
|
+
|
|
hFile = CreateFileW(
|
|
path,
|
|
FILE_READ_ATTRIBUTES, /* desired access */
|
|
@@ -3697,6 +3728,13 @@
|
|
if (path_wchar == NULL)
|
|
return NULL;
|
|
|
|
+ if(!check_GetFinalPathNameByHandle()) {
|
|
+ /* If the OS doesn't have GetFinalPathNameByHandle, return a
|
|
+ NotImplementedError. */
|
|
+ return PyErr_Format(PyExc_NotImplementedError,
|
|
+ "GetFinalPathNameByHandle not available on this platform");
|
|
+ }
|
|
+
|
|
Py_BEGIN_ALLOW_THREADS
|
|
hFile = CreateFileW(
|
|
path_wchar,
|
|
@@ -3716,8 +3754,8 @@
|
|
target path name. */
|
|
while (1) {
|
|
Py_BEGIN_ALLOW_THREADS
|
|
- result_length = GetFinalPathNameByHandleW(hFile, target_path,
|
|
- buf_size, VOLUME_NAME_DOS);
|
|
+ result_length = Py_GetFinalPathNameByHandleW(hFile, target_path,
|
|
+ buf_size, VOLUME_NAME_DOS);
|
|
Py_END_ALLOW_THREADS
|
|
|
|
if (!result_length) {
|