Skip to content

Commit 79bf014

Browse files
committed
[Windows] Fix _fileExists for relative links
A relative link should be determined from the path that it is in, not the current working directory
1 parent 07df806 commit 79bf014

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Foundation/FileManager+Win32.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,15 @@ extension FileManager {
539539
var faAttributes: WIN32_FILE_ATTRIBUTE_DATA = WIN32_FILE_ATTRIBUTE_DATA()
540540
do { faAttributes = try windowsFileAttributes(atPath: path) } catch { return false }
541541
if faAttributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_REPARSE_POINT) == DWORD(FILE_ATTRIBUTE_REPARSE_POINT) {
542-
do { try faAttributes = windowsFileAttributes(atPath: destinationOfSymbolicLink(atPath: path)) } catch { return false }
542+
do {
543+
let contents = try destinationOfSymbolicLink(atPath: path)
544+
let resolvedPath = contents.isAbsolutePath
545+
? contents
546+
: joinPath(prefix: path.deletingLastPathComponent, suffix: contents)
547+
try faAttributes = windowsFileAttributes(atPath: resolvedPath)
548+
} catch {
549+
return false
550+
}
543551
}
544552
if let isDirectory = isDirectory {
545553
isDirectory.pointee = ObjCBool(faAttributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_DIRECTORY) == DWORD(FILE_ATTRIBUTE_DIRECTORY))

0 commit comments

Comments
 (0)