-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Windows] Fix Symbolic Link Creation #2207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
gmittert
commented
May 1, 2019
- Don't error out if the target doesn't exist
- Check the correct path when determining if it's a directory
@swift-ci please test |
Foundation/FileManager+Win32.swift
Outdated
var dwFlags: DWORD = DWORD(SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE) | ||
var dwFlags = DWORD(SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE) | ||
// destPath may not exist in which case we default to creating a file symlink | ||
let faAttributes = (try? windowsFileAttributes(atPath: destPath)) ?? WIN32_FILE_ATTRIBUTE_DATA() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to resolve the final path here ... destPath
needs to be resolved relative to path
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's continue to throw here; we don't know what the target of the symlink will be and we can silently fail later with a symlink being a file symlink with a directory target.
Foundation/FileManager+Win32.swift
Outdated
@@ -286,12 +287,12 @@ extension FileManager { | |||
internal func _canonicalizedPath(toFileAtPath path: String) throws -> String { | |||
var hFile: HANDLE = INVALID_HANDLE_VALUE | |||
path.withCString(encodedAs: UTF16.self) { link in | |||
hFile = CreateFileW(link, GENERIC_READ, DWORD(FILE_SHARE_WRITE), nil, DWORD(OPEN_EXISTING), DWORD(FILE_FLAG_BACKUP_SEMANTICS), nil) | |||
hFile = CreateFileW(link, GENERIC_READ, DWORD(FILE_SHARE_READ | FILE_SHARE_WRITE), nil, DWORD(OPEN_EXISTING), DWORD(FILE_FLAG_BACKUP_SEMANTICS), nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please use
0
instead ofGENERIC_READ
- Please use
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
- Please add a comment to explain the need for the
FILE_FLAG_BACKUP_SEMANTICS
here.
@swift-ci please test and merge |
@swift-ci please test |
Foundation/FileManager+Win32.swift
Outdated
nil, | ||
DWORD(OPEN_EXISTING), | ||
// BACKUP_SEMANTICS are (confusingly) required | ||
// in order to receive a handle to a directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would've put the comment before the CreateFileW
call. BTW, Foundation doesn't do the one parameter per line for the arguments.
- Don't error out if the target doesn't exist - Check the correct path when determining if it's a directory
@swift-ci please test and merge |
1 similar comment
@swift-ci please test and merge |