[pbs-devel] [PATCH proxmox v2] sys: file: use renameat2() from `nix` crate

Christian Ebner c.ebner at proxmox.com
Thu Jul 18 13:19:05 CEST 2024


> On 18.07.2024 12:29 CEST Thomas Lamprecht <t.lamprecht at proxmox.com> wrote:
> 
>  
> Am 12/07/2024 um 09:54 schrieb Christoph Heiss:
> > Saves us from converting the paths to raw C strings ourselves, thus
> > simplifying it quite a bit.
> > 
> > Since the `nix` crate does not provide link() directly, only linkat(),
> > that is used instead - which behaves exactly the same as link() when
> > using AT_FDCWD and an empty flag set.
> > 
> > No functional changes.
> > 
> 
> OK by me in general, but I get the following errors on build (well `cargo check`):
> 
> 
> ```
>     Checking proxmox-sys v0.6.0 (/root/sources/pbs/proxmox/proxmox-sys)
> error[E0603]: struct `AtFlags` is private
>    --> proxmox-sys/src/fs/file.rs:283:30
>     |
> 283 |                 nix::unistd::AtFlags::empty(),
>     |                              ^^^^^^^ private struct
>     |
> note: the struct `AtFlags` is defined here
>    --> /usr/share/cargo/registry/nix-0.26.1/src/unistd.rs:6:30
>     |
> 6   | use crate::fcntl::{at_rawfd, AtFlags};
>     |                              ^^^^^^^
> help: consider importing this struct instead
>     |
> 283 |                 nix::fcntl::AtFlags::empty(),
>     |                 ~~~~~~~~~~~~~~~~~~~
> help: import `AtFlags` directly
>     |
> 283 |                 nix::fcntl::AtFlags(),
>     |                 ~~~~~~~~~~~~~~~~~~~
> 
> error[E0308]: mismatched types
>     --> proxmox-sys/src/fs/file.rs:283:17
>      |
> 278  |             let result = nix::unistd::linkat(
>      |                          ------------------- arguments to this function are incorrect
> ...
> 283  |                 nix::unistd::AtFlags::empty(),
>      |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `LinkatFlags`, found `AtFlags`
>      |
> note: function defined here
>     --> /usr/share/cargo/registry/nix-0.26.1/src/unistd.rs:1252:8
>      |
> 1252 | pub fn linkat<P: ?Sized + NixPath>(
>      |        ^^^^^^
> 
> Some errors have detailed explanations: E0308, E0603.
> For more information about an error, try `rustc --explain E0308`.
> error: could not compile `proxmox-sys` (lib) due to 2 previous errors
> ```
> 
> Seems like you tested this with upstream nix, as the new type only works
> since nix version 0.28, while we still got 0.26.1.
> 
> We might be able to upgrade nix, but that is often quite a bit more
> involved.
> 
> Alternatively we could go with your v1 approach and apply
> 
> ```
> diff --git a/proxmox-sys/src/fs/file.rs b/proxmox-sys/src/fs/file.rs
> index b2d6ddf6..28c7f88b 100644
> --- a/proxmox-sys/src/fs/file.rs
> +++ b/proxmox-sys/src/fs/file.rs
> @@ -280,7 +280,7 @@ pub fn atomic_open_or_create_file<P: AsRef<Path>>(
>                  &temp_file_name,
>                  None,
>                  &path.to_path_buf(),
> -                nix::unistd::AtFlags::empty(),
> +                nix::unistd::LinkatFlags::NoSymlinkFollow,
>              );
>              let _ = nix::unistd::unlink(&temp_file_name);
>              result
> ```
> 
> On top for now.
> 
> Oh, please always test such changes with the crate versions provided by our
> Debian package provided crate registry.
> 

Partially my fault, as I overlooked in my suggestion that linkat() does not accept `AtFlags` in version 0.26.1 just yet [0].
The suggested replacement type is however already there, but the module namespace is incorrect in the patch. Should have been [1].

[0] https://docs.rs/nix/0.26.1/nix/unistd/fn.linkat.html
[1] https://docs.rs/nix/0.26.1/nix/fcntl/struct.AtFlags.html




More information about the pbs-devel mailing list