-
Notifications
You must be signed in to change notification settings - Fork 197
Closed
Description
Consider the following code:
let fm = FileManager()
do {
try fm.createFile(atPath: "test", contents: nil)
try fm.linkItem(atPath: "test", toPath: "test2")
precondition(!fm.fileExists(atPath: "test3"))
try fm.copyItem(atPath: "test2", toPath: "test3")
} catch {
print("\(error)")
exit(EXIT_FAILURE)
}
Running this will produce the following filesystem contents:
E:\symlinktest>dir
...
Directory of E:\symlinktest
...
08/12/2024 02:16 PM 0 test
08/12/2024 02:16 PM <SYMLINK> test2 [test]
08/12/2024 02:16 PM 0 test3
...
AND will throw this error from copyItem:
CocoaError(code: FoundationEssentials.CocoaError.Code(rawValue: 516), userInfo: ["NSFilePath": AnyHashable("test2"), "NSUnderlyingError": AnyHashable(FoundationEssentials.Win32Error(code: 183))])
Somehow, copyItem ALWAYS fails with ERROR_ALREADY_EXISTS
when copying a symlink, even though the destination definitely did not exist prior to the call.
Swift version 6.0-dev (LLVM 31f0cdc6d5ff8a6, Swift aa0786cc7b3190c)
Microsoft Windows [Version 10.0.22631.3958]
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
jakepetroules commentedon Aug 12, 2024
This also appears to be a regression as I don't recall observing this fail with the July snapshot of Swift 6 (but is failing with the August 7 snapshot)
jakepetroules commentedon Aug 12, 2024
Also reproduces with the copyItem call replaced with the same Win32 APIs that swift-foundation is calling internally:
This returns HRESULT 0x80070050 (The file exists)
So I suspect the dwCopyFlags might be invalid. Some potentially relevant docs: https://learn.microsoft.com/en-us/windows/win32/fileio/symbolic-link-effects-on-file-systems-functions
@compnerd Any idea what might be wrong here?
Convert PrivacyInfo.xcprivacy symlinks to files
Convert PrivacyInfo.xcprivacy symlinks to files (#251)