Skip to content

Commit

Permalink
boulder/draft: Handle zip vs tar origins for boulder new
Browse files Browse the repository at this point in the history
Right now we just specialise based on `.zip` suffix but we can
easily add special casing in time and perhaps even check the
actual mimetype. The idea is to reuse this approach for boulders
own unpack code and build a chain of extensions for the `.tar` case
to handle the archive mode and compression helper.

Right now, this unblocks zips for boulder new so yay.

Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed Jan 17, 2025
1 parent af51104 commit e58862d
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions boulder/src/draft/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,36 @@ async fn fetch(url: &Url, output: &Path) -> Result<String, Error> {
}

async fn extract(archive: &Path, destination: &Path) -> Result<(), Error> {
// Attempt extraction. For now, we assume everything is a tarball
let result = Command::new("tar")
.arg("xf")
.arg(archive)
.arg("-C")
.arg(destination)
.output()
.await?;
let extension = archive
.extension()
.map(|e| e.to_string_lossy().to_string())
.unwrap_or_else(|| "tar".to_owned());

// If we can't specialise (.zip, etc) assume its a tar
let result = match extension.as_str() {
"zip" => {
Command::new("unzip")
.arg(archive)
.arg("-d")
.arg(destination)
.output()
.await?
}
_ => {
Command::new("tar")
.arg("xf")
.arg(archive)
.arg("-C")
.arg(destination)
.output()
.await?
}
};

if result.status.success() {
Ok(())
} else {
eprintln!("Command exited with: {}", String::from_utf8_lossy(&result.stderr));
Err(Error::Extract(result.status))
}
}
Expand Down

0 comments on commit e58862d

Please sign in to comment.