-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix Up FileManager Tests on Windows #2277
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
@spevans Is there a particular scenario you're testing for with the file names ending with |
Foundation/NSPathUtilities.swift
Outdated
@@ -345,7 +349,11 @@ extension NSString { | |||
|
|||
let automount = "/var/automount" | |||
resolved = resolved._tryToRemovePathPrefix(automount) ?? resolved | |||
#if os(Windows) | |||
return String(resolved.map { $0 == "\\" ? "/" : $0 }) |
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.
Why change the path separator here?
Foundation/NSURL.swift
Outdated
@@ -32,7 +32,11 @@ private func _standardizedPath(_ path: String) -> String { | |||
if !path.absolutePath { | |||
return path._nsObject.standardizingPath | |||
} | |||
#if os(Windows) | |||
return String(path.map({$0 == "/" ? "\\" : $0})) |
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.
My understanding is that the standardizing should collapse relative components (i.e. ..
should be chased, .
dropped). As such, any reason to not just use PathCchCanonicalizeEx
?
Foundation/NSPathUtilities.swift
Outdated
@@ -118,7 +118,11 @@ extension String { | |||
} | |||
|
|||
internal var absolutePath: Bool { |
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.
Bleh! It would be nice to rename this to isAbsolutePath
.
TestFoundation/TestFileManager.swift
Outdated
if item == "item" { | ||
item1FileAttributes = e.fileAttributes | ||
} else if item == "path2/item" { | ||
item2FileAttributes = e.fileAttributes | ||
} | ||
#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.
Isn't this hunk equivalent to just changing L459 (R) to } else if item == "path2/item" || item == "path2\\item" {
?
TestFoundation/TestFileManager.swift
Outdated
} | ||
#if os(Windows) | ||
XCTAssertEqual(foundItems, Set(["item", "path2", "path2\\item"])) |
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.
I wonder if you can span the Set
over two lines and do an #if os(Windows)
to swap out the third element.
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.
You can't. You can move the set creation elsewhere, or make it mutable and #if os(Windows)
the addition.
Foundation/FileManager+Win32.swift
Outdated
|
||
func findFirstValidFile() -> URL? { | ||
while let url = _stack.popLast() { | ||
let dirFSR = url.withUnsafeFileSystemRepresentation { $0.flatMap { fsr in String(utf8String: fsr) } } ?? "" |
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.
Hmm, this seems pretty expensive.
Foundation/FileManager+Win32.swift
Outdated
func findFirstValidFile() -> URL? { | ||
while let url = _stack.popLast() { | ||
let dirFSR = url.withUnsafeFileSystemRepresentation { $0.flatMap { fsr in String(utf8String: fsr) } } ?? "" | ||
if !FileManager.default.fileExists(atPath: dirFSR, isDirectory: nil) { |
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.
Huh? Should dirFSR
be renamed? If isDirectory
is nil
, then we do not know if it is a file or directory, so it seems to be misleading.
Foundation/FileManager+Win32.swift
Outdated
return nil | ||
|
||
var isDir: ObjCBool = false | ||
let dirFSR = _current.withUnsafeFileSystemRepresentation { $0.flatMap { fsr in String(utf8String: fsr) } } ?? "" |
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.
Again, the dirFSR
is really misleading here. Can we rename this as we do not know what the path points to.
|
@swift-ci please test |
@swift-ci please test |
CoreFoundation/URL.subproj/CFURL.c
Outdated
@@ -4474,7 +4474,7 @@ CFStringRef CFURLCreateStringWithFileSystemPath(CFAllocatorRef allocator, CFURLR | |||
// and do a linked-on-or-later check so we don't break third parties. | |||
// See <rdar://problem/4003028> Converting volume name from POSIX to HFS form fails and | |||
// <rdar://problem/4018895> CF needs to back out 4003028 for icky details. | |||
if ( relPath && CFURLHasDirectoryPath(anURL) && CFStringGetLength(relPath) > 1 && CFStringGetCharacterAtIndex(relPath, CFStringGetLength(relPath)-1) == '/') { | |||
if ( relPath && CFURLHasDirectoryPath(anURL) && CFStringGetLength(relPath) > 1 && CFStringGetCharacterAtIndex(relPath, CFStringGetLength(relPath)-1) == _CFGetSlash()) { |
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.
Since this is from a URL, is this change needed, and if it is from a URL is this not incorrect? CC: @millenomi
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.
Seems like it's not, I've removed that change.
let itemPath1 = basePath + "itemFile1" | ||
#if os(Windows) | ||
// Filenames ending with '.' are not valid on Windows, so don't bother testing them |
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.
@millenomi - what do you think about this?
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.
That's fine.
- Windows directory enumerator now doesn't look in a directory it returns until nextObject is called again - Fixed some path handling platform issues - Properly calculate level
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 looks good to me now.
@millenomi @spevans - any comments on the behavioural changes on Windows for FileManager
?
@swift-ci please test |
@swift-ci please test and merge |
1 similar comment
@swift-ci please test and merge |
returns until nextObject is called again
See SR-10738