file-restore: allow extracting a full pxar archive

If the path for within the archive is empty, assume "/" to extract all
of it.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
Stefan Reiter 2021-04-21 15:18:09 +02:00 committed by Thomas Lamprecht
parent 4d0dc29951
commit 4adf47b606

View File

@ -399,14 +399,16 @@ async fn extract_to_target<T>(
where
T: pxar::accessor::ReadAt + Clone + Send + Sync + Unpin + 'static,
{
let path = if path.is_empty() { b"/" } else { path };
let root = decoder.open_root().await?;
let file = root
.lookup(OsStr::from_bytes(&path))
.lookup(OsStr::from_bytes(path))
.await?
.ok_or_else(|| format_err!("error opening '{:?}'", path))?;
if let Some(target) = target {
extract_sub_dir(target, decoder, OsStr::from_bytes(&path), verbose).await?;
extract_sub_dir(target, decoder, OsStr::from_bytes(path), verbose).await?;
} else {
match file.kind() {
pxar::EntryKind::File { .. } => {
@ -416,7 +418,7 @@ where
create_zip(
tokio::io::stdout(),
decoder,
OsStr::from_bytes(&path),
OsStr::from_bytes(path),
verbose,
)
.await?;