From 79bf014c40aa8a15df2a7aa486663ee518bae771 Mon Sep 17 00:00:00 2001 From: Gwen Mittertreiner Date: Fri, 12 Jul 2019 13:52:18 -0700 Subject: [PATCH] [Windows] Fix _fileExists for relative links A relative link should be determined from the path that it is in, not the current working directory --- Foundation/FileManager+Win32.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Foundation/FileManager+Win32.swift b/Foundation/FileManager+Win32.swift index bb78e1468b..6061a5161d 100644 --- a/Foundation/FileManager+Win32.swift +++ b/Foundation/FileManager+Win32.swift @@ -539,7 +539,15 @@ extension FileManager { var faAttributes: WIN32_FILE_ATTRIBUTE_DATA = WIN32_FILE_ATTRIBUTE_DATA() do { faAttributes = try windowsFileAttributes(atPath: path) } catch { return false } if faAttributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_REPARSE_POINT) == DWORD(FILE_ATTRIBUTE_REPARSE_POINT) { - do { try faAttributes = windowsFileAttributes(atPath: destinationOfSymbolicLink(atPath: path)) } catch { return false } + do { + let contents = try destinationOfSymbolicLink(atPath: path) + let resolvedPath = contents.isAbsolutePath + ? contents + : joinPath(prefix: path.deletingLastPathComponent, suffix: contents) + try faAttributes = windowsFileAttributes(atPath: resolvedPath) + } catch { + return false + } } if let isDirectory = isDirectory { isDirectory.pointee = ObjCBool(faAttributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_DIRECTORY) == DWORD(FILE_ATTRIBUTE_DIRECTORY))