Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions registry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ github-markdown-toc.backends = [
"aqua:ekalinin/github-markdown-toc",
"asdf:skyzyx/asdf-github-markdown-toc"
]
github-markdown-toc.test = ["gh-md-toc --version", "{{version}}"]
gitleaks.description = "Find secrets with Gitleaks"
gitleaks.backends = ["aqua:gitleaks/gitleaks", "asdf:jmcvetta/asdf-gitleaks"]
gitleaks.test = ["gitleaks --version", "gitleaks version {{version}}"]
Expand Down Expand Up @@ -1697,6 +1698,7 @@ license-plist.backends = [
]
lima.description = "Linux virtual machines, with a focus on running containers"
lima.backends = ["aqua:lima-vm/lima", "asdf:CrouchingMuppet/asdf-lima"]
lima.test = ["lima --version", "limactl version {{version}}"]
linkerd.description = "Ultralight, security-first service mesh for Kubernetes. Main repo for Linkerd 2.x"
linkerd.backends = ["aqua:linkerd/linkerd2", "asdf:kforsthoevel/asdf-linkerd"]
liqoctl.backends = ["aqua:liqotech/liqo", "asdf:pdemagny/asdf-liqoctl"]
Expand Down
122 changes: 56 additions & 66 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use eyre::bail;
use filetime::{FileTime, set_file_times};
use flate2::read::GzDecoder;
use itertools::Itertools;
use path_absolutize::Absolutize;
use std::sync::LazyLock as Lazy;
use tar::Archive;
use walkdir::WalkDir;
Expand Down Expand Up @@ -675,75 +674,66 @@ pub fn untar(archive: &Path, dest: &Path, opts: &TarOptions) -> Result<()> {
};
if format == TarFormat::Zip {
unzip(archive, dest)?;
match opts.strip_components {
0 => {}
1 => {
let entries = ls(dest)?
.into_iter()
.map(|p| ls(&p))
.collect::<Result<Vec<_>>>()?
.into_iter()
.flatten()
.collect::<Vec<_>>();
for entry in entries {
let mut new_dest = dest.to_path_buf();
new_dest.push(entry.file_name().unwrap());
fs::rename(entry, new_dest)?;
}
} else {
debug!("tar -xf {} -C {}", archive.display(), dest.display());
if let Some(pr) = &opts.pr {
pr.set_message(format!(
"extract {}",
archive.file_name().unwrap().to_string_lossy()
));
}
let tar = open_tar(format, archive)?;
let err = || {
let archive = display_path(archive);
let dest = display_path(dest);
format!("failed to extract tar: {archive} to {dest}")
};
// TODO: put this back in when we can read+write in parallel
// let mut cur = Cursor::new(vec![]);
// let mut total = 0;
// loop {
// let mut buf = Cursor::new(vec![0; 1024 * 1024]);
// let n = tar.read(buf.get_mut()).wrap_err_with(err)?;
// cur.get_mut().extend_from_slice(&buf.get_ref()[..n]);
// if n == 0 {
// break;
// }
// if let Some(pr) = &opts.pr {
// total += n as u64;
// pr.set_length(total);
// }
// }
create_dir_all(dest).wrap_err_with(err)?;
for entry in Archive::new(tar).entries().wrap_err_with(err)? {
let mut entry = entry.wrap_err_with(err)?;
trace!("extracting {}", entry.path().wrap_err_with(err)?.display());
entry.unpack_in(dest).wrap_err_with(err)?;
if let Some(pr) = &opts.pr {
pr.set_length(entry.raw_file_position());
}
_ => bail!("strip-components not supported for zip archives"),
}
return Ok(());
}
debug!("tar -xf {} -C {}", archive.display(), dest.display());
if let Some(pr) = &opts.pr {
pr.set_message(format!(
"extract {}",
archive.file_name().unwrap().to_string_lossy()
));
}
let tar = open_tar(format, archive)?;
let err = || {
let archive = display_path(archive);
let dest = display_path(dest);
format!("failed to extract tar: {archive} to {dest}")
};
// TODO: put this back in when we can read+write in parallel
// let mut cur = Cursor::new(vec![]);
// let mut total = 0;
// loop {
// let mut buf = Cursor::new(vec![0; 1024 * 1024]);
// let n = tar.read(buf.get_mut()).wrap_err_with(err)?;
// cur.get_mut().extend_from_slice(&buf.get_ref()[..n]);
// if n == 0 {
// break;
// }
// if let Some(pr) = &opts.pr {
// total += n as u64;
// pr.set_length(total);
// }
// }
for entry in Archive::new(tar).entries().wrap_err_with(err)? {
let mut entry = entry.wrap_err_with(err)?;
let path: PathBuf = entry
.path()
.wrap_err_with(err)?
.components()
.skip(opts.strip_components)
.filter(|c| c.as_os_str() != ".")
.collect::<PathBuf>()
.absolutize_virtually(dest)?
.to_path_buf();
create_dir_all(path.parent().unwrap()).wrap_err_with(err)?;
trace!("extracting {}", display_path(&path));
entry.unpack(&path).wrap_err_with(err)?;
if let Some(pr) = &opts.pr {
pr.set_length(entry.raw_file_position());
// if let Some(pr) = &opts.pr {
// pr.set_position(total);
// }
}
match opts.strip_components {
0 => {}
Comment thread
risu729 marked this conversation as resolved.
1 => {
let entries = ls(dest)?
.into_iter()
.map(|p| ls(&p))
.collect::<Result<Vec<_>>>()?
.into_iter()
.flatten()
.collect::<Vec<_>>();
for entry in entries {
let mut new_dest = dest.to_path_buf();
new_dest.push(entry.file_name().unwrap());
fs::rename(entry, new_dest)?;
}
}
_ => bail!("strip-components > 1 is not supported"),
}
// if let Some(pr) = &opts.pr {
// pr.set_position(total);
// }
Ok(())
}

Expand Down
Loading