Skip to content

Commit

Permalink
fix: ensure zips without root are handled (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
swarnimarun authored Dec 18, 2023
1 parent 4bc012f commit 756861e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,25 @@ pub async fn fetch_sources(
fn extract(archive: &Path, target_directory: &Path) -> Result<std::process::Output, SourceError> {
let tar_exe = which::which("tar").map_err(|_| SourceError::TarNotFound)?;

let output = Command::new(&tar_exe)
let mut command = Command::new(&tar_exe);
command
.arg("-xf")
.arg(archive.as_os_str())
.arg("--preserve-permissions")
.arg("--strip-components=1")
.arg("-C")
.arg(target_directory.as_os_str())
.output()?;
.arg("--preserve-permissions");

// zip files don't need to have root directory (they can though, but we can't strip-component
// unconditionally as it's generally not the case)
if !archive
.extension()
.map(|ex| ex.eq("zip"))
.unwrap_or_default()
{
command.arg("--strip-components=1");
}

command.arg("-C").arg(target_directory.as_os_str());

let output = command.output()?;

if !output.status.success() {
return Err(SourceError::ExtractionError(format!(
Expand Down
8 changes: 7 additions & 1 deletion src/source/url_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ pub(crate) async fn url_src(source: &UrlSource, cache_dir: &Path) -> Result<Path
}

let response = reqwest::get(source.url().clone()).await?;

let mut file = std::fs::File::create(&cache_name)?;

let mut content = Cursor::new(response.bytes().await?);
Expand Down Expand Up @@ -167,6 +166,13 @@ mod tests {
fn test_cache_name() {
let cases =
vec![
(
"https://cache-redirector.jetbrains.com/download.jetbrains.com/idea/jdbc-drivers/web/snowflake-3.13.27.zip",
Checksum::Sha256(rattler_digest::parse_digest_from_hex::<Sha256>(
"6a15e95ee7e6c55b862dab9758ea803350aa2e3560d6183027b0c29919fcab18",
).unwrap()),
"snowflake-3.13.27_6a15e95e.zip",
),
(
"https://example.com/example.tar.gz",
Checksum::Sha256(rattler_digest::parse_digest_from_hex::<Sha256>(
Expand Down

0 comments on commit 756861e

Please sign in to comment.