Skip to content

Commit 2efcbcc

Browse files
committed
Foundation: correct directory iteration on Windows
The path that was being constructed would elide the penultimate arc in the path as the base URL was not marked as a directory. As such, it was assumed to be a file URL, and making a URL relative to it would truncate the previously last arc. Append the path component instead and explicitly indicate if it is a directory component when building the URL as we already have the information on hand. This repairs the directory traversal on Windows. The bug was identified by the DocC test suite on Windows.
1 parent b70418c commit 2efcbcc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Diff for: Sources/Foundation/FileManager+Win32.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,9 @@ extension FileManager {
989989
ffd.dwFileAttributes & DWORD(FILE_ATTRIBUTE_HIDDEN) == DWORD(FILE_ATTRIBUTE_HIDDEN) {
990990
continue
991991
}
992-
_stack.append(URL(fileURLWithPath: file, relativeTo: _lastReturned))
992+
993+
let isDirectory = ffd.dwFileAttributes & DWORD(FILE_ATTRIBUTE_DIRECTORY) == DWORD(FILE_ATTRIBUTE_DIRECTORY)
994+
_stack.append(_lastReturned.appendingPathComponent(file, isDirectory: isDirectory))
993995
} while FindNextFileW(handle, &ffd)
994996
}
995997
return firstValidItem()

0 commit comments

Comments
 (0)