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

create_dir_all is not thread safe/races with itself. #47

Closed
gczzdc opened this issue Dec 20, 2022 · 0 comments
Closed

create_dir_all is not thread safe/races with itself. #47

gczzdc opened this issue Dec 20, 2022 · 0 comments

Comments

@gczzdc
Copy link

gczzdc commented Dec 20, 2022

the relevant section of create_dir_all (https://github.com/manuel-woelker/rust-vfs/blob/master/src/path.rs#L228):

if !self.fs.fs.exists(directory)? {
  self.fs.fs.create_dir(directory)?;
}

Suppose I have a Vec<(&str, &vfspath)>, and I want to concurrently write the strings to the paths, which may or may not exist. Naively, one approach is to run create_dir_all on the paths' parents and then write out to each path. But doing that can race because thread A creates a common ancestor path between the check and the create call from thread B.

Sort of similar to rust-lang/rust#33707

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

No branches or pull requests

1 participant