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

[SR-12737] FileManager.createDirectory can throw fileWriteFileExists even when withIntermediateDirectories is true #3256

Closed
jackhl opened this issue May 5, 2020 · 1 comment

Comments

@jackhl
Copy link
Member

jackhl commented May 5, 2020

Previous ID SR-12737
Radar None
Original Reporter @jackhl
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: ac32b4e0e0c5550241eb96ad90efcbf7

relates to:

  • SR-12272 FileManager temporary directory creation not thread-safe on Linux

Issue Description:

In concurrent code, FileManager.createDirectory can throw fileWriteFileExists even when withIntermediateDirectories is true, which is a violation of the documented API contract.

This happens because the implementation falls for the classic check-then-run concurrency trap and does not double-check the result of mkdir. On macOS, this was fixed in rdar://23925981.

internal func _createDirectory(atPath path: String, withIntermediateDirectories createIntermediates: Bool, attributes: [FileAttributeKey : Any]? = [:]) throws {

if mkdir(pathFsRep, S_IRWXU | S_IRWXG | S_IRWXO) != 0 {                           
    throw _NSErrorWithErrno(errno, reading: false, path: path)

The code should check for EEXISTS before throwing.

@spevans
Copy link
Collaborator

spevans commented Jun 23, 2020

This should be resolved by #2700

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants