From 1bd624ecb9ea2caec8d08ef585edd7e45d3c2b7e Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Thu, 3 Nov 2022 22:53:25 +0100 Subject: [PATCH] backup: Add option --ignore-devid --- src/backend/ignore.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/backend/ignore.rs b/src/backend/ignore.rs index 57b80cc..1e39f7f 100644 --- a/src/backend/ignore.rs +++ b/src/backend/ignore.rs @@ -19,6 +19,7 @@ pub struct LocalSource { builder: WalkBuilder, walker: Walk, with_atime: bool, + ignore_devid: bool, cache: UsersCache, } @@ -31,6 +32,11 @@ pub struct LocalSourceOptions { #[merge(strategy = merge::bool::overwrite_false)] with_atime: bool, + /// Don't save device ID for files and directories + #[clap(long)] + #[merge(strategy = merge::bool::overwrite_false)] + ignore_devid: bool, + /// Glob pattern to exclude/include (can be specified multiple times) #[clap(long, short = 'g', help_heading = "EXCLUDE OPTIONS")] #[merge(strategy = merge::vec::overwrite_empty)] @@ -129,16 +135,15 @@ impl LocalSource { }); } - let with_atime = opts.with_atime; - let cache = UsersCache::new(); let builder = walk_builder; let walker = builder.build(); Ok(Self { builder, walker, - with_atime, - cache, + with_atime: opts.with_atime, + ignore_devid: opts.ignore_devid, + cache: UsersCache::new(), }) } } @@ -172,12 +177,17 @@ impl Iterator for LocalSource { } item => item, } - .map(|e| map_entry(e?, self.with_atime, &self.cache)) + .map(|e| map_entry(e?, self.with_atime, self.ignore_devid, &self.cache)) } } // map_entry: turn entry into (Path, Node) -fn map_entry(entry: DirEntry, with_atime: bool, cache: &UsersCache) -> Result<(PathBuf, Node)> { +fn map_entry( + entry: DirEntry, + with_atime: bool, + ignore_devid: bool, + cache: &UsersCache, +) -> Result<(PathBuf, Node)> { let name = entry.file_name(); let m = entry.metadata()?; @@ -201,7 +211,7 @@ fn map_entry(entry: DirEntry, with_atime: bool, cache: &UsersCache) -> Result<(P let size = if m.is_dir() { 0 } else { m.len() }; let mode = map_mode_to_go(m.mode()); let inode = m.ino(); - let device_id = m.dev(); + let device_id = if ignore_devid { 0 } else { m.dev() }; let links = if m.is_dir() { 0 } else { m.nlink() }; let meta = Metadata {