Skip to content

Commit

Permalink
fix(extract): need to rewind NamedTempFile before extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 6, 2023
1 parent 45ab773 commit eb8c0af
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions crates/nassun/src/tarball.rs
@@ -1,4 +1,4 @@
use std::io::Read;
use std::io::{Read, Seek};
#[cfg(not(target_arch = "wasm32"))]
use std::io::Write;
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -185,14 +185,16 @@ pub(crate) enum TempTarball {
#[cfg(not(target_arch = "wasm32"))]
impl TempTarball {
pub(crate) fn extract_to_dir(
self,
mut self,
dir: &Path,
tarball_integrity: Option<Integrity>,
cache: Option<&Path>,
) -> Result<Integrity> {
let mut file_index = serde_json::Map::new();
let mut drain_buf = [0u8; 1024 * 8];

self.rewind()?;

let mut reader = std::io::BufReader::new(self);
let mut integrity = IntegrityOpts::new().algorithm(ssri::Algorithm::Sha512);
let mut tee_reader = io_tee::TeeReader::new(&mut reader, &mut integrity);
Expand All @@ -212,7 +214,7 @@ impl TempTarball {

for file in files {
let mut file = file.map_err(|e| {
NassunError::ExtractIoError(e, None, "reading entry from tarball".into())
NassunError::ExtractIoError(e, Some(PathBuf::from(dir)), "reading entry from tarball".into())
})?;
let header = file.header();
let entry_path = header.path().map_err(|e| {
Expand Down Expand Up @@ -343,6 +345,16 @@ impl std::io::Read for TempTarball {
}
}

#[cfg(not(target_arch = "wasm32"))]
impl std::io::Seek for TempTarball {
fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result<u64> {
match self {
TempTarball::File(f) => f.seek(pos),
TempTarball::Memory(m) => m.seek(pos),
}
}
}

#[cfg(not(target_arch = "wasm32"))]
fn strip_one(path: &Path) -> Option<&Path> {
let mut comps = path.components();
Expand Down

0 comments on commit eb8c0af

Please sign in to comment.