-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement _removeItem in terms of DirectoryEnumerator #2002
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
Conversation
@swift-ci please test |
Foundation/FileManager.swift
Outdated
fts_close(stream) | ||
if (URL(fileURLWithPath: itemPath).hasDirectoryPath) { | ||
#if os(Windows) | ||
let result = _NS_rmdir(itemPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to just fileprivate let _NS_rmdir = rmdir
on non-Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And similarly for _NS_unlink
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or fileprivate let rmdir = _NS_rundir
on Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
9c8bfdc
to
99ec935
Compare
Foundation/FileManager.swift
Outdated
return _NS_unlink(path) != 0 | ||
#else | ||
return unlink(path) != 0 | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can also be unlink(path)
now right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eeeyup
99ec935
to
591661f
Compare
Wont this spend a lot of effort to convert every file entry from file system representation into a URL then convert it back again to remove it? Im not sure of the benefit of this change. |
It does add extra URL calls, however, it's one less use of fts and means the same codepath works across Windows/Darwin/Linux. How expensive is converting to a URL? I'm still okay with #1976 if adding an extra conversion is too expensive to be worth it. |
Could also do the |
@swift-ci please test |
I can remove all the URL conversions in _removeItem, but the issue is still that NSURLDirectoryEnumerator gives back URLs rather than Strings so it will still be doing the conversion there and back. |
Yes, but that is a feature since the paths need to be converted to FSRs prior to the |
@swift-ci please test |
591661f
to
5114418
Compare
Okay, I've removed the unneeded URL conversions in _removeItem, the only one remaining is the needed one to create the Enumerator. |
@swift-ci please test |
1 similar comment
@swift-ci please test |
It fails when creating a symlink for swiftpm... I don't think it's related?
|
@swift-ci please test |
1 similar comment
@swift-ci please test |
Ah hold up a bit, this is actually broken on Linux, I've repro'd it locally. Just having issues setting up a Linux environment where I can test it properly. |
You are calling the Another point regarding the FSR, is that the I think this approach in general is wrong, for an internal helper like this it should just use the best per-OS solution to delete a file or directory structure. |
I actually agree, and I think I'd rather do #1976 instead. @compnerd if we really care about a single codepath, one other alternative would be to have an fts shim and implement that on Windows and call through to the real thing on everything else, but that might be more effort than it's worth. |
I don't think that we want to re-implement FTS on top of the Windows APIs. Would it not be possible to actually have an internal method to avoid the overheads of the FTS translation and the stating? If not, then I suppose that we can split the file into two and have a |
Closing in favour of #2117 |
Alternate implementation to #1976 that uses DirectoryEnumerator