Skip to content

Commit 6114ed0

Browse files
authored
Merge pull request #2674 from compnerd/code-brown
Foundation: correct error code for invalid symlink on Windows
2 parents 4346168 + 54b00a1 commit 6114ed0

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Sources/Foundation/FileManager+Win32.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,15 @@ extension FileManager {
295295
destPath.isAbsolutePath ? destPath
296296
: joinPath(prefix: path.deletingLastPathComponent,
297297
suffix: destPath)
298+
299+
// NOTE: windowsfileAttributes will throw if the destPath is not
300+
// found. Since on Windows, you are required to know the type
301+
// of the symlink target (file or directory) during creation,
302+
// and assuming one or the other doesn't make a lot of sense, we
303+
// allow it to throw, thus disallowing the creation of broken
304+
// symlinks on Windows is the target is of unknown type.
298305
guard let faAttributes = try? windowsFileAttributes(atPath: resolvedDest) else {
299-
// Note: windowsfileAttributes will throw if the destPath is not found.
300-
// Since on Windows, you are required to know the type of the symlink
301-
// target (file or directory) during creation, and assuming one or the
302-
// other doesn't make a lot of sense, we allow it to throw, thus
303-
// disallowing the creation of broken symlinks on Windows is the target
304-
// is of unknown type.
305-
throw _NSErrorWithWindowsError(GetLastError(), reading: true, paths: [path, resolvedDest])
306+
throw _NSErrorWithWindowsError(GetLastError(), reading: true, paths: [path, destPath])
306307
}
307308
if faAttributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_DIRECTORY) == DWORD(FILE_ATTRIBUTE_DIRECTORY) {
308309
dwFlags |= DWORD(SYMBOLIC_LINK_FLAG_DIRECTORY)

0 commit comments

Comments
 (0)