Skip to content

Implement NSURLDirectoryEnumerator for Windows #1966

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
Mar 15, 2019

Conversation

gmittert
Copy link
Contributor

@gmittert gmittert commented Mar 4, 2019

Uses FindFirstFileW repeatedly to enumerate the directories. The unix implementation via fts does a preorder traversal, though the order that the children are visited in seems random. The Windows implementation also shares this behaviour: FindNextFile isn't guaranteed to be alphabetical depending on the file system.

@gmittert
Copy link
Contributor Author

gmittert commented Mar 4, 2019

@compnerd @millenomi

&& file != ".."
&& (_options.contains(.skipsHiddenFiles)
&& (ffd.dwFileAttributes & DWORD(FILE_ATTRIBUTE_HIDDEN) == 0))) {
files.append(URL(fileReferenceLiteralResourceName: "\(directory.absoluteString)\\\(file)"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean URL(fileURLWithPath:)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I did :s

internal class NSURLDirectoryEnumerator : DirectoryEnumerator {
internal typealias ErrorHandler = /* @escaping */ (URL, Error) -> Bool
#if os(Windows)
var _url : URL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is _url needed? It doesnt look to be used outside of init() since it is also stored in _stack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, removed.

@gmittert gmittert force-pushed the ForestForTheTrees branch from ffa6c31 to 7c6fb29 Compare March 5, 2019 00:48
@millenomi
Copy link
Contributor

@swift-ci please test

@gmittert gmittert force-pushed the ForestForTheTrees branch from 7c6fb29 to 3b9c7c2 Compare March 7, 2019 00:45
@gmittert
Copy link
Contributor Author

gmittert commented Mar 7, 2019

Added a missing FindClose on the FindFirstFile handle.

override func nextObject() -> Any? {
let o = innerEnumerator.nextObject()
guard let url = o as? URL else {
return nil
}

#if os(Windows)
NSUnimplemented()
let path = url.path.replacingOccurrences(of: baseURL.path+"\\", with: "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really would prefer that we use PathRelativePathToW here instead.

var _errorHandler : ((URL, Error) -> Bool)?
var _stack: [URL]
var _current: URL?
var _root_depth : Int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_rootDepth to follow the style please (or _depth if you so like).

@gmittert gmittert force-pushed the ForestForTheTrees branch from 3b9c7c2 to 6788430 Compare March 7, 2019 23:02
@gmittert gmittert force-pushed the ForestForTheTrees branch from 6788430 to aa88f36 Compare March 11, 2019 23:33
@gmittert gmittert force-pushed the ForestForTheTrees branch from aa88f36 to f2d6ee1 Compare March 12, 2019 22:33
@gmittert
Copy link
Contributor Author

Removed all the absolute strings and path concatting and used the path functions instead.

@gmittert gmittert force-pushed the ForestForTheTrees branch from f2d6ee1 to e548967 Compare March 13, 2019 00:46
@compnerd
Copy link
Member

@swift-ci please test

@millenomi millenomi merged commit 25d5cd6 into swiftlang:master Mar 15, 2019
@gmittert gmittert deleted the ForestForTheTrees branch March 15, 2019 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants