-
Notifications
You must be signed in to change notification settings - Fork 34
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 directory if not exists, and return Dir
#372
Comments
The reason for this is that the underying platform APIs don't have such a function. There is no way to atomically obtain a directory handle to a newly-created directory on Unix-family platforms, and possibly not in Windows either. If we added such a function in cap-std, it would have the same TOCTOU hazard. |
On Windows, |
Thanks. We still can't do it on Unix though. It's also worth mentioning that cap-std is following std here, where create_dir similarly does not return a handle, presumably for the same reason. |
There can only be a TOCTOU if there's already a way for a potentially hostile other process to swap the directory after Let's discard the "same UID" case...anyone trying to isolate while having concurrent write access to the same directory starts to get arbitrarily hard. For I can't think of a real world situation where software would be at risk. Certainly it'd make sense to add to the documentation of such a function that it's not guaranteed that "the same" directory that was created was opened...but in practice the people who want to do this are just going to call the two functions anyways since that's all they can do, and I don't see why it makes sense to deny them the "sugar" for such a theoretical problem.
What "handle" would it return? |
It's not necessarily one Unix user attacking another. It can also be a user typing
Unix today doesn't give you a handle (or "file descriptor", which I'm using interchangeably in this thread) from |
Is there a simple way to create a directory if it does not yet exist and to return the
Dir
?Something along the lines of:
I couldn't find a
create_dir_with
that would allow specifying e.g.OpenOptions
, and all the create_dir functions don't return theDir
itself.If not, would the project be open to contributions on this?
The text was updated successfully, but these errors were encountered: