summaryrefslogtreecommitdiffstats
path: root/platform_utils_win32.py
diff options
context:
space:
mode:
authorРоман Донченко <dpb@corrigendum.ru>2019-03-21 23:45:59 +0300
committerРоман Донченко <dpb@corrigendum.ru>2019-03-21 23:45:59 +0300
commita84df061609ed937c0bbc45491fd352d62caa0fc (patch)
treec6b85de126cb5ba3acf0b5b91482c19fd93a97ed /platform_utils_win32.py
parente57f1146de4324dc0f9c6c95fb9897b0e78dfd36 (diff)
downloadgit-repo-a84df061609ed937c0bbc45491fd352d62caa0fc.tar.gz
platform_utils_win32: remove an unnecessary workaround
The comment in _create_symlink is incorrect. The return value of CreateSymbolicLink is as documented, it was just declared with the wrong return type. The actual return type is BOOLEAN, not BOOL. Fixing this allows us to simplify the code a bit. Change-Id: I4d2190a50d45ba41dd9814bf7079a5784fc0a366
Diffstat (limited to 'platform_utils_win32.py')
-rw-r--r--platform_utils_win32.py17
1 files changed, 5 insertions, 12 deletions
diff --git a/platform_utils_win32.py b/platform_utils_win32.py
index a6431216..7ab2bf04 100644
--- a/platform_utils_win32.py
+++ b/platform_utils_win32.py
@@ -17,7 +17,7 @@ import errno
17 17
18from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof 18from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof
19from ctypes import c_buffer 19from ctypes import c_buffer
20from ctypes.wintypes import BOOL, LPCWSTR, DWORD, HANDLE, POINTER, c_ubyte 20from ctypes.wintypes import BOOL, BOOLEAN, LPCWSTR, DWORD, HANDLE, POINTER, c_ubyte
21from ctypes.wintypes import WCHAR, USHORT, LPVOID, Structure, Union, ULONG 21from ctypes.wintypes import WCHAR, USHORT, LPVOID, Structure, Union, ULONG
22from ctypes.wintypes import byref 22from ctypes.wintypes import byref
23 23
@@ -33,7 +33,7 @@ ERROR_PRIVILEGE_NOT_HELD = 1314
33 33
34# Win32 API entry points 34# Win32 API entry points
35CreateSymbolicLinkW = kernel32.CreateSymbolicLinkW 35CreateSymbolicLinkW = kernel32.CreateSymbolicLinkW
36CreateSymbolicLinkW.restype = BOOL 36CreateSymbolicLinkW.restype = BOOLEAN
37CreateSymbolicLinkW.argtypes = (LPCWSTR, # lpSymlinkFileName In 37CreateSymbolicLinkW.argtypes = (LPCWSTR, # lpSymlinkFileName In
38 LPCWSTR, # lpTargetFileName In 38 LPCWSTR, # lpTargetFileName In
39 DWORD) # dwFlags In 39 DWORD) # dwFlags In
@@ -145,19 +145,12 @@ def create_dirsymlink(source, link_name):
145 145
146 146
147def _create_symlink(source, link_name, dwFlags): 147def _create_symlink(source, link_name, dwFlags):
148 # Note: Win32 documentation for CreateSymbolicLink is incorrect. 148 if not CreateSymbolicLinkW(link_name, source, dwFlags | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE):
149 # On success, the function returns "1".
150 # On error, the function returns some random value (e.g. 1280).
151 # The best bet seems to use "GetLastError" and check for error/success.
152 CreateSymbolicLinkW(link_name, source, dwFlags | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)
153 code = get_last_error()
154 if code != ERROR_SUCCESS:
155 # See https://github.com/golang/go/pull/24307/files#diff-b87bc12e4da2497308f9ef746086e4f0 149 # See https://github.com/golang/go/pull/24307/files#diff-b87bc12e4da2497308f9ef746086e4f0
156 # "the unprivileged create flag is unsupported below Windows 10 (1703, v10.0.14972). 150 # "the unprivileged create flag is unsupported below Windows 10 (1703, v10.0.14972).
157 # retry without it." 151 # retry without it."
158 CreateSymbolicLinkW(link_name, source, dwFlags) 152 if not CreateSymbolicLinkW(link_name, source, dwFlags):
159 code = get_last_error() 153 code = get_last_error()
160 if code != ERROR_SUCCESS:
161 error_desc = FormatError(code).strip() 154 error_desc = FormatError(code).strip()
162 if code == ERROR_PRIVILEGE_NOT_HELD: 155 if code == ERROR_PRIVILEGE_NOT_HELD:
163 raise OSError(errno.EPERM, error_desc, link_name) 156 raise OSError(errno.EPERM, error_desc, link_name)