-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
dirfd dir operations (3/4) #160533
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
base: main
Are you sure you want to change the base?
dirfd dir operations (3/4) #160533
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,12 @@ impl Dir { | |
| with_native_path(path, &|path| Self::open_with_native(path, opts)) | ||
| } | ||
|
|
||
| pub fn open_for_traversal(path: &Path) -> io::Result<Self> { | ||
| let mut opts = OpenOptions::new(); | ||
| opts.access_mode(c::FILE_TRAVERSE); | ||
| with_native_path(path, &|path| Self::open_with_native(path, &opts)) | ||
| } | ||
|
|
||
| pub fn open_file(&self, path: &Path, opts: &OpenOptions) -> io::Result<File> { | ||
| // NtCreateFile will fail if given an absolute path and a non-null RootDirectory | ||
| if path.is_absolute() { | ||
|
|
@@ -87,6 +93,24 @@ impl Dir { | |
| self.rename_native(&from, to_dir, &to, is_dir) | ||
| } | ||
|
|
||
| pub fn create_dir(&self, path: &Path) -> io::Result<()> { | ||
| let mut opts = OpenOptions::new(); | ||
| opts.read(true); | ||
| opts.write(true); | ||
| opts.create_new(true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's preferable to chain this and write it as: let opts = OpenOptions::new().read(true)
.write(true)
.create_new(true);
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, got you. |
||
| self.open_dir(path, &opts).map(|_| ()) | ||
| } | ||
|
|
||
| pub fn open_dir(&self, path: &Path, opts: &OpenOptions) -> io::Result<Self> { | ||
| let path = to_u16s_without_nul(&path)?; | ||
| self.open_file_native(&path, &opts, true).map(|handle| Self { handle }) | ||
| } | ||
|
|
||
| pub fn remove_dir(&self, path: &Path) -> io::Result<()> { | ||
| let path = to_u16s_without_nul(&path)?; | ||
| self.remove_native(&path, true) | ||
| } | ||
|
|
||
| fn open_with_native(path: &WCStr, opts: &OpenOptions) -> io::Result<Self> { | ||
| let creation = opts.get_creation_mode()?; | ||
| let sa = c::SECURITY_ATTRIBUTES { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we follow symlinks, right? Should we note that here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do follow them, but I don't think we need to note it.
Dir::openandFile::open(and maybe others) also follow symlinks without documenting that fact. If we decide that we should note it, that's a follow-up PR.