Skip to content
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

Recore FileManager on top of FoundationEssentials.FileManager #4957

Merged
merged 2 commits into from
May 17, 2024

Conversation

jmschonfeld
Copy link
Contributor

This PR removes all of the functionality from FileManager that is already surfaced via FoundationEssentials. There are still some pieces (namely those that require URLResourceValues) that are not available in FoundationEssentials yet, and those are left here in an extension on FileManager

This change depends on swiftlang/swift-foundation#609, I'll update the dependency's commit hash once that PR has been approved and is merged

@@ -1385,15 +1393,11 @@ class TestFileManager : XCTestCase {

XCTAssertThrowsError(try fm.attributesOfItem(atPath: "")) {
let code = ($0 as? CocoaError)?.code
XCTAssertEqual(code, .fileReadInvalidFileName)
XCTAssertEqual(code, .fileReadNoSuchFile)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we simply throw a different error now, or is the former API somehow missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We throw an error now. Previously the behavior for these empty paths differed between Darwin and non-Darwin. The swift-foundation implementation takes the behavior from Darwin and so this updates the test expectations accordingly. Previously, getting the file system representation of an empty string unconditionally threw .fileReadInvalidFileName, but now we just create en empty cstring and provide it to the underlying system API and let it determine how to handle an empty path (which in most cases results in specifying that the file doesn't exist, unless you're working with a directory in which I believe some cases it can be considered the current directory)

XCTAssertNil(filemanger.homeDirectory(forUser: "someuser"))
XCTAssertNil(filemanger.homeDirectory(forUser: ""))
XCTAssertNotNil(filemanger.homeDirectory(forUser: "someuser"))
XCTAssertNotNil(filemanger.homeDirectory(forUser: ""))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is another change in behavior, correct?

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, similar to the above this aligns non-Darwin behavior with Darwin behavior. Previously we returned nil on non-Darwin for a non-existent user but now we always fallback to /var/empty as a last resort if the user doesn't exist

@jmschonfeld jmschonfeld merged commit 6f4c134 into swiftlang:package May 17, 2024
@jmschonfeld jmschonfeld deleted the filemanager-recore branch May 17, 2024 21:55
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.

2 participants