Skip to content

FileManager fixes #1481

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 22, 2018
Merged

FileManager fixes #1481

merged 1 commit into from
Mar 22, 2018

Conversation

spevans
Copy link
Contributor

@spevans spevans commented Mar 16, 2018

  • Use a common subfunction to read directory contents in
    contentsOfDirectory(atPath:) and subpathsOfDirectory(atPath:).

  • Use readdir_r() instead of readdir().

  • Call fileSystemRepresentation(withPath:) on the requested directory
    to match behaviour on Darwin.

  • Replace the test case of a bad directory using "" with "/..." which
    now fails the precondition (to match Darwin).

- Use a common subfunction to read directory contents in
  contentsOfDirectory(atPath:) and subpathsOfDirectory(atPath:).

- Use readdir_r() instead of readdir().

- Call fileSystemRepresentation(withPath:) on the requested directory
  to match behaviour on Darwin.

- Replace the test case of a bad directory using "" with "/..." which
  now fails the precondition (to match Darwin).
@spevans
Copy link
Contributor Author

spevans commented Mar 16, 2018

@swift-ci please test

@spevans spevans requested a review from millenomi March 16, 2018 11:03
@@ -442,8 +442,8 @@ class TestFileManager : XCTestCase {
}

do {
let _ = try fm.contentsOfDirectory(atPath: "")

// Check a bad path fails
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the change here, for the record?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its for compatibility with Darwin's native Foundation. This call will throw an exception under native Foundation as the filename is passed through fileSystemRepresentation(withPath:) which treats nil and "" as invalid paths. This PR modifies contentsOfDirectory(atPath:) and subpathsOfDirectory(atPath:) to now also pass the path through this function so "" is now going to fail the precondition(path != "", "Empty path argument") check.

FYI, if you open the Xcode project DarwinCompatibilityTests in the swift-corelibs-foundation directory you can run all of the tests as unit tests against native Foundation to see what differences currently exist.

@@ -492,8 +492,8 @@ class TestFileManager : XCTestCase {
}

do {
let _ = try fm.subpathsOfDirectory(atPath: "")

// Check a bad path fails
Copy link
Contributor

Choose a reason for hiding this comment

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

As above.

@spevans
Copy link
Contributor Author

spevans commented Mar 22, 2018

@swift-ci please test and merge

@swift-ci swift-ci merged commit 6682092 into swiftlang:master Mar 22, 2018
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.

3 participants