diff options
author | Роман Донченко <dpb@corrigendum.ru> | 2019-03-21 23:45:59 +0300 |
---|---|---|
committer | Роман Донченко <dpb@corrigendum.ru> | 2019-03-21 23:45:59 +0300 |
commit | a84df061609ed937c0bbc45491fd352d62caa0fc (patch) | |
tree | c6b85de126cb5ba3acf0b5b91482c19fd93a97ed /platform_utils_win32.py | |
parent | e57f1146de4324dc0f9c6c95fb9897b0e78dfd36 (diff) | |
download | git-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.py | 17 |
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 | ||
18 | from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof | 18 | from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof |
19 | from ctypes import c_buffer | 19 | from ctypes import c_buffer |
20 | from ctypes.wintypes import BOOL, LPCWSTR, DWORD, HANDLE, POINTER, c_ubyte | 20 | from ctypes.wintypes import BOOL, BOOLEAN, LPCWSTR, DWORD, HANDLE, POINTER, c_ubyte |
21 | from ctypes.wintypes import WCHAR, USHORT, LPVOID, Structure, Union, ULONG | 21 | from ctypes.wintypes import WCHAR, USHORT, LPVOID, Structure, Union, ULONG |
22 | from ctypes.wintypes import byref | 22 | from 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 |
35 | CreateSymbolicLinkW = kernel32.CreateSymbolicLinkW | 35 | CreateSymbolicLinkW = kernel32.CreateSymbolicLinkW |
36 | CreateSymbolicLinkW.restype = BOOL | 36 | CreateSymbolicLinkW.restype = BOOLEAN |
37 | CreateSymbolicLinkW.argtypes = (LPCWSTR, # lpSymlinkFileName In | 37 | CreateSymbolicLinkW.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 | ||
147 | def _create_symlink(source, link_name, dwFlags): | 147 | def _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) |