[pbs-devel] [PATCH v2 proxmox-backup 2/2] fix: #4761: introduce overwrite bitflags for fine grained overwrites

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Aug 4 14:30:36 CEST 2023


This has some trailing whitespace and needs a `rustfmt`.

Also, see inline comments:

On Tue, Aug 01, 2023 at 12:34:12PM +0200, Christian Ebner wrote:
> Adds OverwriteFlags for granular control of which entry types should
> overwrite entries present on the filesystem during a restore.
> 
> The original overwrite flag is refactored in order to cover all of the
> other cases.
> 
> Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
> ---
> changes since v1:
> * rebased and refactored to current master
> 
>  pbs-client/src/catalog_shell.rs   |  9 ++++--
>  pbs-client/src/pxar/extract.rs    | 47 +++++++++++++++++++++++--------
>  pbs-client/src/pxar/mod.rs        |  2 +-
>  proxmox-backup-client/src/main.rs | 28 +++++++++++++++++-
>  pxar-bin/src/main.rs              | 32 +++++++++++++++++++--
>  5 files changed, 101 insertions(+), 17 deletions(-)
> 
(...)
> diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs
> index c1e7b417..6faf0b54 100644
> --- a/pbs-client/src/pxar/extract.rs
> +++ b/pbs-client/src/pxar/extract.rs
> @@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
>  use std::sync::{Arc, Mutex};
>  
>  use anyhow::{bail, format_err, Context, Error};
> +use bitflags::bitflags;
>  use nix::dir::Dir;
>  use nix::fcntl::OFlag;
>  use nix::sys::stat::Mode;
> @@ -33,10 +34,34 @@ pub struct PxarExtractOptions<'a> {
>      pub match_list: &'a [MatchEntry],
>      pub extract_match_default: bool,
>      pub allow_existing_dirs: bool,
> -    pub overwrite: bool,
> +    pub overwrite_flags: OverwriteFlags,
>      pub on_error: Option<ErrorHandler>,
>  }
>  
> +
> +bitflags! {
> +    pub struct OverwriteFlags: u8 {
> +        /// Disable all
> +        const NONE = 0x0;

bitflags provides a `OverwriteFlags::empty()`, so I'd drop the `NONE`
variant

> +        /// Overwrite existing entries file content 
> +        const FILE = 0x1;
> +        /// Overwrite existing entry with symlink
> +        const SYMLINK = 0x2;
> +        /// Overwrite existing entry with hardlink
> +        const HARDLINK = 0x4;
> +        /// Enable all
> +        const ALL = OverwriteFlags::FILE.bits()
> +            | OverwriteFlags::SYMLINK.bits()
> +            | OverwriteFlags::HARDLINK.bits();

and bitflags also provides a `OverwriteFlags::all()`, so I'd drop `ALL`
as well ;-)

> +    }
> +}
> +
> +impl Default for OverwriteFlags {
> +    fn default() -> Self {
> +        OverwriteFlags::NONE

since this is `0`, you can just `derive(Default)` instead

> +    }
> +}
> +
>  pub type ErrorHandler = Box<dyn FnMut(Error) -> Result<(), Error> + Send>;
>  
>  pub fn extract_archive<T, F>(
> @@ -141,7 +166,7 @@ where
(...)

Otherwise LGTM





More information about the pbs-devel mailing list