Skip to content

Commit dd9910b

Browse files
authored
FoundationEssentials: ensure that the path exists before iteration (#665)
When performing a `subpathsOfDirectory`, ensure that the path exists. On the non-Windows path, `_FTSSequence` will perform the initial `statvfs` during construction which obscured this requirement. We instead explicitly inline this call in the implementation. This repairs further test failures.
1 parent 9371cbf commit dd9910b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/FoundationEssentials/FileManager/FileManager+Directories.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ extension _FileManagerImpl {
159159

160160
func subpathsOfDirectory(atPath path: String) throws -> [String] {
161161
#if os(Windows)
162+
try path.withNTPathRepresentation {
163+
var faAttributes: WIN32_FILE_ATTRIBUTE_DATA = .init()
164+
guard GetFileAttributesExW($0, GetFileExInfoStandard, &faAttributes) else {
165+
throw CocoaError.errorWithFilePath(path, win32: GetLastError(), reading: true)
166+
}
167+
}
168+
162169
var results: [String] = []
163170
for item in _Win32DirectoryContentsSequence(path: path, appendSlashForDirectory: true) {
164171
results.append(item.fileName)

0 commit comments

Comments
 (0)