Skip to content

FoundationEssentials: account for relative paths in iteration #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ extension _FileManagerImpl {
func subpathsOfDirectory(atPath path: String) throws -> [String] {
#if os(Windows)
var results: [String] = []
let iterator = _Win32DirectoryContentsSequence(path: path, appendSlashForDirectory: true).makeIterator()
while let item = iterator.next() {
for item in _Win32DirectoryContentsSequence(path: path, appendSlashForDirectory: true) {
results.append(item.fileName)
if item.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == FILE_ATTRIBUTE_DIRECTORY &&
item.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT != FILE_ATTRIBUTE_REPARSE_POINT {
Expand All @@ -176,7 +175,7 @@ extension _FileManagerImpl {
}
defer { LocalFree(pwszSubPath) }

results.append(contentsOf: try subpathsOfDirectory(atPath: item.fileName).map {
results.append(contentsOf: try subpathsOfDirectory(atPath: String(decodingCString: pwszSubPath!, as: UTF16.self)).map {
var pwszFullPath: PWSTR? = nil
_ = PathAllocCombine(item.fileName, $0, PATHCCH_ALLOW_LONG_PATHS, &pwszFullPath)
defer { LocalFree(pwszFullPath) }
Expand Down