-
Notifications
You must be signed in to change notification settings - Fork 13.3k
dirfd: initial quick and dirty implementation for unix #139514
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: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @workingjubilee. Use |
The job Click to see the possible cause of the failure (guessed by this bot)
|
r? libs |
@@ -1353,6 +1360,25 @@ impl Seek for Arc<File> { | |||
} | |||
} | |||
|
|||
#[unstable(feature = "dirfd", issue = "120426")] |
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.
This goes on each of the functions, not the impl block
/// Opens a file relative to this directory. | ||
pub fn open<P: AsRef<Path>>(&self, path: P) -> io::Result<File> { | ||
self.inner.open(path).map(|f| File { inner: f }) | ||
} | ||
/// Opens a file relative to this directory with the specified options. | ||
pub fn open_with<P: AsRef<Path>>(&self, path: P, opts: &OpenOptions) -> io::Result<File> { | ||
self.inner.open_with(path, &opts.0).map(|f| File { inner: f }) | ||
} |
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.
Could you please add examples here, as well as tests? Tests can go in std/src/fs/tests.rs
.
@@ -116,6 +116,13 @@ pub struct File { | |||
inner: fs_imp::File, | |||
} | |||
|
|||
#[unstable(feature = "dirfd", issue = "120426")] | |||
#[cfg(target_family = "unix")] |
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 shouldn't/can't have platform-gated config in fs
, tidy would probably complain about this if CI got that far. It's okay to stub out less popular platforms for now with FIXME
s, but I think the initial implementation should come with Windows support. There are some guidelines at #120426 (comment), feel free to ask questions on Zulip if you get stuck.
|
||
// pub fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<()> | ||
// pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(&self, from: P, to_dir: &Self, to: Q) -> Result<()> | ||
// pub fn remove_file<P: AsRef<Path>>(&self, path: P) -> Result<()> | ||
// pub fn remove_dir<P: AsRef<Path>>(&self, path: P) -> Result<()> | ||
// pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(&self, original: P, link: Q) |
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.
It's probably better to delete this, instead of possibly forgetting to remove them later.
@@ -116,6 +116,13 @@ pub struct File { | |||
inner: fs_imp::File, | |||
} | |||
|
|||
#[unstable(feature = "dirfd", issue = "120426")] | |||
#[cfg(target_family = "unix")] | |||
/// An object providing access to a directory on the filesystem. |
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.
Could you elaborate the documentation here a bit? At least make it clear that this is a handle, and what happens on drop (similar to File
).
|
||
// dirfd isn't supported everywhere | ||
#[cfg(not(any( | ||
miri, |
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 handle such missing platforms by returning errors instead of not having the methods exist at all
☔ The latest upstream changes (presumably #140608) made this pull request unmergeable. Please resolve the merge conflicts. |
Tracking issue: #120426
As per this comment, this issue needs someone to start work on an implementation, so I've implemented a couple functions for UNIX. There's a lot more work to be done here (most of the feature), so I'd love some guidance on what needs fixing in this PR and any notes on how to proceed. Thanks!