Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure zips without root are handled #425

Merged
merged 1 commit into from
Dec 18, 2023
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
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