Skip to content

Commit

Permalink
feat: avoid writing decompressed copy of downloaded crate releases
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini committed Apr 3, 2024
1 parent 78f3609 commit 48b2043
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,15 @@ fn main() -> Result<()> {
}
}

//
// Decompress the crate `.tar.gz` into a `.tar`
//

let decompressed_crate_path = crate_dir.join(format!("{}.tar", package.version));
if !decompressed_crate_path.try_exists()? {
println!("Decompressing {} v{}", package.name, package.version);

let mut file_decompressed = GzDecoder::new(File::open(&crate_path)?);

let mut tmp_decompressed_crate_path = decompressed_crate_path.clone();
tmp_decompressed_crate_path.as_mut_os_string().push(".tmp");
let mut decompressed_crate_file = File::create(&tmp_decompressed_crate_path)?;
io::copy(&mut file_decompressed, &mut decompressed_crate_file)?;
decompressed_crate_file.flush()?;
drop(decompressed_crate_file);

fs::rename(tmp_decompressed_crate_path, &decompressed_crate_path)?;
}

//
// Read `.cargo_vcs_info.json` and `Cargo.toml`
//

let mut cargo_vcs_info = None;
let mut cargo_toml = None;

let mut tar = Archive::new(File::open(&decompressed_crate_path)?);
for entry in tar.entries_with_seek()? {
let mut tar = Archive::new(GzDecoder::new(File::open(&crate_path)?));
for entry in tar.entries()? {
let mut entry = entry?;
let path = entry
.path()?
Expand Down Expand Up @@ -475,9 +455,9 @@ fn main() -> Result<()> {
// Hash file contents
//

let mut crates_io_tar = Archive::new(File::open(&decompressed_crate_path)?);
let mut crates_io_tar = Archive::new(GzDecoder::new(File::open(&crate_path)?));
let mut crates_io_hashes = BTreeMap::new();
for file in crates_io_tar.entries_with_seek()? {
for file in crates_io_tar.entries()? {
let file = file?;
let path = file.path()?.into_owned();
if path.ends_with(".cargo_vcs_info.json") {
Expand Down

0 comments on commit 48b2043

Please sign in to comment.