diff --git a/registry.toml b/registry.toml index 6bb97f06e0..ebbbb9464f 100644 --- a/registry.toml +++ b/registry.toml @@ -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}}"] @@ -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"] diff --git a/src/file.rs b/src/file.rs index 4bf26af866..e8dc444e23 100644 --- a/src/file.rs +++ b/src/file.rs @@ -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; @@ -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::>>()? - .into_iter() - .flatten() - .collect::>(); - 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::() - .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 => {} + 1 => { + let entries = ls(dest)? + .into_iter() + .map(|p| ls(&p)) + .collect::>>()? + .into_iter() + .flatten() + .collect::>(); + 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(()) }