Skip to content

[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

Merged
merged 1 commit into from
May 3, 2019

Conversation

gmittert
Copy link
Contributor

@gmittert 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

@gmittert
Copy link
Contributor Author

gmittert commented May 1, 2019

@swift-ci please test

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()
Copy link
Member

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.

Copy link
Member

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.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please use 0 instead of GENERIC_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.

@gmittert gmittert force-pushed the SymlinksAreHard branch from 3ccda36 to de755eb Compare May 3, 2019 04:12
@gmittert
Copy link
Contributor Author

gmittert commented May 3, 2019

@swift-ci please test and merge

@gmittert
Copy link
Contributor Author

gmittert commented May 3, 2019

@swift-ci please test

nil,
DWORD(OPEN_EXISTING),
// BACKUP_SEMANTICS are (confusingly) required
// in order to receive a handle to a directory
Copy link
Member

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
@gmittert gmittert force-pushed the SymlinksAreHard branch from de755eb to efd11ea Compare May 3, 2019 15:34
@gmittert
Copy link
Contributor Author

gmittert commented May 3, 2019

@swift-ci please test and merge

1 similar comment
@gmittert
Copy link
Contributor Author

gmittert commented May 3, 2019

@swift-ci please test and merge

@swift-ci swift-ci merged commit dea5c12 into swiftlang:master May 3, 2019
@gmittert gmittert deleted the SymlinksAreHard branch June 26, 2019 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants