Skip to content

Commit

Permalink
Be more forgiving to a file that fails to extract, just keep going
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamVenner committed Oct 1, 2023
1 parent 1795084 commit 9dafe1e
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions fastgmad-lib/src/extract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,30 @@ impl ExtractGma for StandardExtractGma {
}
};

if let Some(parent) = path.parent() {
if parent != conf.out {
std::fs::create_dir_all(parent)
.map_err(|error| fastgmad_io_error!(while "creating directory for GMA entry", error: error, path: parent))?;
let w = (|| {
if let Some(parent) = path.parent() {
if parent != conf.out {
std::fs::create_dir_all(parent)
.map_err(|error| fastgmad_io_error!(while "creating directory for GMA entry", error: error, path: parent))?;
}
}
}

let mut take = r.take(*size as u64);
let mut w = File::create(path).map_err(|error| fastgmad_io_error!(while "creating file for GMA entry", error: error, path: path))?;
File::create(path).map_err(|error| fastgmad_io_error!(while "creating file for GMA entry", error: error, path: path))
})();

let mut w = match w {
Ok(w) => w,
Err(err) => {
log::warn!("Skipping GMA entry ({err})");

r.skip(*size as u64)
.map_err(|error| fastgmad_io_error!(while "skipping past GMA entry data", error: error))?;

continue;
}
};

let mut take = r.take(*size as u64);
std::io::copy(&mut take, &mut w).map_err(|error| fastgmad_io_error!(while "copying GMA entry data", error: error, path: path))?;

w.flush()
Expand Down Expand Up @@ -432,7 +446,6 @@ impl GmaEntry {
log::info!(
"warning: skipping GMA entry with incompatible file path: {:?} ({err})",
String::from_utf8_lossy(&path),
err
);
None
}
Expand Down

0 comments on commit 9dafe1e

Please sign in to comment.