Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/Foundation/FileManager+Win32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,9 @@ extension FileManager {
ffd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN == FILE_ATTRIBUTE_HIDDEN {
continue
}
_stack.append(URL(fileURLWithPath: file, relativeTo: _lastReturned))

let isDirectory = ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == FILE_ATTRIBUTE_DIRECTORY && ffd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT != FILE_ATTRIBUTE_REPARSE_POINT
_stack.append(_lastReturned.appendingPathComponent(file, isDirectory: isDirectory))
} while FindNextFileW(handle, &ffd)
}
return firstValidItem()
Expand Down
18 changes: 17 additions & 1 deletion Tests/Foundation/Tests/TestFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,22 @@ class TestFileManager : XCTestCase {
XCTFail("Failed to clean up files")
}
}


func test_contentsOfDirectoryEnumeration() throws {
let fm = FileManager.default

let root = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(NSUUID().uuidString, isDirectory: true)
let subdirectory = root.appendingPathComponent("subdirectory", isDirectory: true)
let file = subdirectory.appendingPathComponent("file", isDirectory: false)
try? fm.removeItem(at: root)

try XCTAssertNoThrow(fm.createDirectory(at: subdirectory, withIntermediateDirectories: true, attributes: nil))
try XCTAssertNoThrow(fm.createFile(atPath: file.path, contents: Data(), attributes: nil))
let contents = try XCTUnwrap(fm.contentsOfDirectory(at: root, includingPropertiesForKeys: [.isDirectoryKey], options: [.skipsHiddenFiles]))
XCTAssertEqual(contents.count, 1)
XCTAssertEqual(contents, [subdirectory])
}

func test_subpathsOfDirectoryAtPath() {
let fm = FileManager.default
let path = NSTemporaryDirectory() + "testdir"
Expand Down Expand Up @@ -2032,6 +2047,7 @@ VIDEOS=StopgapVideos
("test_directoryEnumerator", test_directoryEnumerator),
("test_pathEnumerator",test_pathEnumerator),
("test_contentsOfDirectoryAtPath", test_contentsOfDirectoryAtPath),
("test_contentsOfDirectoryEnumeration", test_contentsOfDirectoryEnumeration),
("test_subpathsOfDirectoryAtPath", test_subpathsOfDirectoryAtPath),
("test_copyItemAtPathToPath", test_copyItemAtPathToPath),
("test_linkItemAtPathToPath", testExpectedToFailOnAndroid(test_linkItemAtPathToPath, "Android doesn't allow hard links")),
Expand Down