mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Windows: Add support for creating symlinks as an unprivileged user
See https://blogs.windows.com/buildingapps/2016/12/02/symlinks-windows-10/ for announcement of new flag. This change follow the same pattern as what was done in "go": https://github.com/golang/go/pull/24307/files#diff-b87bc12e4da2497308f9ef746086e4f0 Change-Id: If1e99fefdd3f787598e695731019c34b9bfcd1c2
This commit is contained in:
parent
e469a0c741
commit
2b42d288c0
@ -41,6 +41,8 @@ CreateSymbolicLinkW.argtypes = (LPCWSTR, # lpSymlinkFileName In
|
||||
# Symbolic link creation flags
|
||||
SYMBOLIC_LINK_FLAG_FILE = 0x00
|
||||
SYMBOLIC_LINK_FLAG_DIRECTORY = 0x01
|
||||
# symlink support for CreateSymbolicLink() starting with Windows 10 (1703, v10.0.14972)
|
||||
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE = 0x02
|
||||
|
||||
GetFileAttributesW = kernel32.GetFileAttributesW
|
||||
GetFileAttributesW.restype = DWORD
|
||||
@ -147,6 +149,12 @@ def _create_symlink(source, link_name, dwFlags):
|
||||
# On success, the function returns "1".
|
||||
# On error, the function returns some random value (e.g. 1280).
|
||||
# The best bet seems to use "GetLastError" and check for error/success.
|
||||
CreateSymbolicLinkW(link_name, source, dwFlags | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)
|
||||
code = get_last_error()
|
||||
if code != ERROR_SUCCESS:
|
||||
# See https://github.com/golang/go/pull/24307/files#diff-b87bc12e4da2497308f9ef746086e4f0
|
||||
# "the unprivileged create flag is unsupported below Windows 10 (1703, v10.0.14972).
|
||||
# retry without it."
|
||||
CreateSymbolicLinkW(link_name, source, dwFlags)
|
||||
code = get_last_error()
|
||||
if code != ERROR_SUCCESS:
|
||||
|
Loading…
Reference in New Issue
Block a user