Skip to content

[Windows] Fix FileManager.removeItem #2203

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
May 3, 2019

Conversation

gmittert
Copy link
Contributor

@gmittert gmittert commented May 1, 2019

  • Get the fsr of the passed in path before using it
  • Add the correct path to the directory stack

@gmittert gmittert requested a review from compnerd May 1, 2019 17:14
@gmittert
Copy link
Contributor Author

gmittert commented May 1, 2019

@swift-ci please test

@@ -405,30 +405,37 @@ extension FileManager {
guard alreadyConfirmed || shouldRemoveItemAtPath(path, isURL: isURL) else {
return
}
let faAttributes = try windowsFileAttributes(atPath: path)
let url = URL(fileURLWithPath: path)
var fsrBuf: UnsafeMutableBufferPointer<WCHAR> = UnsafeMutableBufferPointer.allocate(capacity: path.length * 2)
Copy link
Member

Choose a reason for hiding this comment

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

Let's use an array instead

Copy link
Contributor Author

@gmittert gmittert May 1, 2019

Choose a reason for hiding this comment

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

Sounds good! Done.

@gmittert
Copy link
Contributor Author

gmittert commented May 1, 2019

@swift-ci please test

1 similar comment
@gmittert
Copy link
Contributor Author

gmittert commented May 1, 2019

@swift-ci please test

let url = URL(fileURLWithPath: path)
var fsrBuf: [WCHAR] = Array<WCHAR>(repeating: 0, count: Int(MAX_PATH))
_CFURLGetWideFileSystemRepresentation(url._cfObject, false, &fsrBuf, Int(MAX_PATH))
let length = fsrBuf.firstIndex(where: {$0 == 0}) ?? (path.length * 2)
Copy link
Member

Choose a reason for hiding this comment

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

This is probably better written as:

let length = wcslen_s(&path, fsrBuf.count)

- Get the fsr of the passed in path before using it
- Add the correct path to the directory stack
@gmittert
Copy link
Contributor Author

gmittert commented May 3, 2019

@swift-ci please test and merge

1 similar comment
@gmittert
Copy link
Contributor Author

gmittert commented May 3, 2019

@swift-ci please test and merge

@gmittert
Copy link
Contributor Author

gmittert commented May 3, 2019

@swift-ci please test linux platform

@gmittert
Copy link
Contributor Author

gmittert commented May 3, 2019

@swift-ci please test and merge

@swift-ci swift-ci merged commit cef3bbd into swiftlang:master May 3, 2019
@gmittert gmittert deleted the removeErrors branch June 26, 2019 21:37
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