pxar: implement allow_existing_dirs for pxar decoder

By default, restoring an archive will fail if files with the same filename
already exist in the target directory.

By setting the allow_existing_dirs flag, the restore will not fail if an
existing directory is encountered.
The metadata (permissions, acls, ...) of the existing directory will be set
to the ones from the archive.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner
2019-07-29 14:01:45 +02:00
committed by Dietmar Maurer
parent 46d5aa0a09
commit 6a87910949
3 changed files with 15 additions and 7 deletions

View File

@ -34,6 +34,7 @@ use crate::tools::xattr;
pub struct SequentialDecoder<'a, R: Read, F: Fn(&Path) -> Result<(), Error>> {
reader: &'a mut R,
feature_flags: u64,
allow_existing_dirs: bool,
skip_buffer: Vec<u8>,
callback: F,
}
@ -48,11 +49,16 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F
Self {
reader,
feature_flags,
allow_existing_dirs: false,
skip_buffer,
callback,
}
}
pub fn set_allow_existing_dirs(&mut self, allow: bool) {
self.allow_existing_dirs = allow;
}
pub (crate) fn get_reader_mut(&mut self) -> & mut R {
self.reader
}
@ -632,7 +638,7 @@ impl <'a, R: Read, F: Fn(&Path) -> Result<(), Error>> SequentialDecoder<'a, R, F
let dir = if filename.is_empty() {
nix::dir::Dir::openat(pfd, ".", OFlag::O_DIRECTORY, Mode::empty())?
} else {
dir_mkdirat(pfd, filename, true)
dir_mkdirat(pfd, filename, !self.allow_existing_dirs)
.map_err(|err| format_err!("unable to open directory {:?} - {}", full_path, err))?
};
(Some(dir.as_raw_fd()), Some(dir))