Conversation
|
Also, I haven't added the changelog yet because I wasn't sure what my PR number would be. I'll go ahead and add that once I get some input on what the API should look like. |
bd3a7f1 to
54c97de
Compare
|
Hi, thanks for this, I will take a look at this PR this weekend:) |
|
Hi, thanks for the PR and thoughts on the API design:)
Yeah, this is bad and we should avoid it.
Yeah, a builder pattern for
A draft code would be something like this: #[repr(transparent)]
pub struct OpenHow(libc::open_how);
pub struct OpenHowBuilder {
open_how: libc::open_how,
}
impl OpenHowBuilder {
pub fn new() -> Self {
// SAFETY:
// From the manual: https://man7.org/linux/man-pages/man2/open_how.2type.html
//
// > Therefore, a user must zero-fill this structure on initialization.
//
// Initializing `open_how` with 0s is valid and a necessity.
let zero_inited = unsafe {
std::mem::MaybeUninit::zeroed().assume_init()
};
Self {
open_how: zero_inited
}
}
pub fn with_flags(&mut self, flags: nix::fcntl::OFlag) -> &mut Self {
let flags = flags.bits();
self.open_how.flags = flags.try_into().expect("failed to cast it to u64");
self
}
pub fn with_mode(&mut self, mode: nix::sys::stat::Mode) -> &mut Self {
let mode = mode.bits();
self.open_how.mode = mode.try_into().expect("failed to cast it to u64");
self
}
pub fn with_resolve(&mut self, resolve: nix::fcntl::ResolveFlag) -> &mut Self {
let resolve = resolve.bits();
self.open_how.resolve = resolve;
self
}
// We can add new methods for future kernel extensions
pub fn build(self) -> OpenHow {
OpenHow(self.open_how)
}
} |
54c97de to
c68cd0b
Compare
Whoops, that's a big oversight on my part! Thanks for catching it. I went with a I think the slightly more interesting choice is having Thanks for the quick review. :) |
d394b5d to
1b49aba
Compare
|
Sorry for all the force pushes. I switched to using |
1b49aba to
68dce83
Compare
|
Looking at CI it looks like there are tier3 failures for unrelated things and some failures where the syscall is returning UPDATE: oops, I put |
68dce83 to
5bc3dc1
Compare
Yeah, they are unrelated and fixed in #2344.
I guess no |
Adds an openat2 function with an OpenHow and ResolveFlag options for configuring path resolution. Fixes nix-rust#1400.
5bc3dc1 to
54a7eb6
Compare
What does this PR do
Adds support for openat2 on linux. Includes a new
ResolveFlagstruct to pass resolve flags, which is passed directly to the newfcntl::openat2function.libc::open_howisn't exposed in any way here, which will mean this API needs to change if there's an update that extendslibc::open_howwith new fields.Given that the whole point of
libc::open_howis that it's extensible, I'm not sure that this is the right way to go about adding this API. I could be convinced to go back and add something that looks more like the stdlib'sOpenOptionsthat would allow adding more arguments to this function without a breaking change. I would love some input/direction here.Fixes #1400.
Checklist:
CONTRIBUTING.md