src/pxar/encoder.rs: add new skip_lost_and_found parameter
This commit is contained in:
parent
6c3c9bceb5
commit
5b72c9b4f7
@ -153,10 +153,11 @@ fn backup_directory<P: AsRef<Path>>(
|
||||
chunk_size: Option<usize>,
|
||||
device_set: Option<HashSet<u64>>,
|
||||
verbose: bool,
|
||||
skip_lost_and_found: bool,
|
||||
crypt_config: Option<Arc<CryptConfig>>,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let pxar_stream = PxarBackupStream::open(dir_path.as_ref(), device_set, verbose)?;
|
||||
let pxar_stream = PxarBackupStream::open(dir_path.as_ref(), device_set, verbose, skip_lost_and_found)?;
|
||||
let chunk_stream = ChunkStream::new(pxar_stream, chunk_size);
|
||||
|
||||
let (tx, rx) = mpsc::channel(10); // allow to buffer 10 chunks
|
||||
@ -419,6 +420,8 @@ fn create_backup(
|
||||
|
||||
let all_file_systems = param["all-file-systems"].as_bool().unwrap_or(false);
|
||||
|
||||
let skip_lost_and_found = param["skip-lost-and-found"].as_bool().unwrap_or(false);
|
||||
|
||||
let verbose = param["verbose"].as_bool().unwrap_or(false);
|
||||
|
||||
let chunk_size_opt = param["chunk-size"].as_u64().map(|v| (v*1024) as usize);
|
||||
@ -543,6 +546,7 @@ fn create_backup(
|
||||
chunk_size_opt,
|
||||
devices.clone(),
|
||||
verbose,
|
||||
skip_lost_and_found,
|
||||
crypt_config.clone(),
|
||||
)?;
|
||||
}
|
||||
@ -1251,6 +1255,9 @@ fn main() {
|
||||
.optional(
|
||||
"verbose",
|
||||
BooleanSchema::new("Verbose output.").default(false))
|
||||
.optional(
|
||||
"skip-lost-and-found",
|
||||
BooleanSchema::new("Skip lost+found directory").default(false))
|
||||
.optional(
|
||||
"host-id",
|
||||
StringSchema::new("Use specified ID for the backup group name ('host/<id>'). The default is the system hostname."))
|
||||
|
@ -181,7 +181,7 @@ fn create_archive(
|
||||
feature_flags ^= pxar::CA_FORMAT_WITH_ACL;
|
||||
}
|
||||
|
||||
pxar::Encoder::encode(source, &mut dir, &mut writer, devices, verbose, feature_flags)?;
|
||||
pxar::Encoder::encode(source, &mut dir, &mut writer, devices, verbose, false, feature_flags)?;
|
||||
|
||||
writer.flush()?;
|
||||
|
||||
|
@ -37,7 +37,7 @@ impl Drop for PxarBackupStream {
|
||||
|
||||
impl PxarBackupStream {
|
||||
|
||||
pub fn new(mut dir: Dir, path: PathBuf, device_set: Option<HashSet<u64>>, verbose: bool) -> Result<Self, Error> {
|
||||
pub fn new(mut dir: Dir, path: PathBuf, device_set: Option<HashSet<u64>>, verbose: bool, skip_lost_and_found: bool) -> Result<Self, Error> {
|
||||
|
||||
let (rx, tx) = nix::unistd::pipe()?;
|
||||
|
||||
@ -49,7 +49,7 @@ impl PxarBackupStream {
|
||||
|
||||
let child = thread::spawn(move|| {
|
||||
let mut writer = unsafe { std::fs::File::from_raw_fd(tx) };
|
||||
if let Err(err) = pxar::Encoder::encode(path, &mut dir, &mut writer, device_set, verbose, pxar::CA_FORMAT_DEFAULT) {
|
||||
if let Err(err) = pxar::Encoder::encode(path, &mut dir, &mut writer, device_set, verbose, skip_lost_and_found, pxar::CA_FORMAT_DEFAULT) {
|
||||
let mut error = error2.lock().unwrap();
|
||||
*error = Some(err.to_string());
|
||||
}
|
||||
@ -65,12 +65,12 @@ impl PxarBackupStream {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn open(dirname: &Path, device_set: Option<HashSet<u64>>, verbose: bool) -> Result<Self, Error> {
|
||||
pub fn open(dirname: &Path, device_set: Option<HashSet<u64>>, verbose: bool, skip_lost_and_found: bool) -> Result<Self, Error> {
|
||||
|
||||
let dir = nix::dir::Dir::open(dirname, OFlag::O_DIRECTORY, Mode::empty())?;
|
||||
let path = std::path::PathBuf::from(dirname);
|
||||
|
||||
Self::new(dir, path, device_set, verbose)
|
||||
Self::new(dir, path, device_set, verbose, skip_lost_and_found)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,7 @@ impl <'a, W: Write> Encoder<'a, W> {
|
||||
writer: &'a mut W,
|
||||
device_set: Option<HashSet<u64>>,
|
||||
verbose: bool,
|
||||
skip_lost_and_found: bool, // fixme: should be a feature flag ??
|
||||
feature_flags: u64,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
@ -127,7 +128,11 @@ impl <'a, W: Write> Encoder<'a, W> {
|
||||
|
||||
if verbose { println!("{:?}", me.full_path()); }
|
||||
|
||||
me.encode_dir(dir, &stat, magic, Vec::new())?;
|
||||
let mut excludes = Vec::new();
|
||||
if skip_lost_and_found {
|
||||
excludes.push(PxarExcludePattern::from_line(b"**/lost+found").unwrap().unwrap());
|
||||
}
|
||||
me.encode_dir(dir, &stat, magic, excludes)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ fn run_test(dir_name: &str) -> Result<(), Error> {
|
||||
|
||||
let path = std::path::PathBuf::from(dir_name);
|
||||
|
||||
Encoder::encode(path, &mut dir, &mut writer, None, false, CA_FORMAT_DEFAULT)?;
|
||||
Encoder::encode(path, &mut dir, &mut writer, None, false, false, CA_FORMAT_DEFAULT)?;
|
||||
|
||||
Command::new("cmp")
|
||||
.arg("--verbose")
|
||||
|
Loading…
Reference in New Issue
Block a user