extract the d3d descriptors and cover the sweep and guard paths
This commit is contained in:
@@ -360,3 +360,35 @@ fn extract_ffmpeg_from_zip(archive_path: &Path, dest: &Path) -> Result<()> {
|
||||
}
|
||||
bail!("ffmpeg.exe not found inside the zip archive");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Stands in for the body of extract_ffmpeg_from_7z: it builds a scratch
|
||||
/// directory, arms the guard, then leaves through the `?` the way a failed
|
||||
/// extraction does.
|
||||
fn fails_with_guard_alive(scratch: &Path) -> Result<()> {
|
||||
fs::create_dir_all(scratch).context("create scratch")?;
|
||||
let _guard = DirGuard(scratch.to_path_buf());
|
||||
fs::write(scratch.join("ffmpeg.exe"), b"x").context("write payload")?;
|
||||
bail!("deliberate extraction failure")
|
||||
}
|
||||
|
||||
/// The scratch tree used to be removed only on the success path, so a failed
|
||||
/// bootstrap left the whole unpacked ffmpeg build sitting in temp/.
|
||||
#[test]
|
||||
fn dir_guard_removes_scratch_even_on_early_exit() {
|
||||
let dir = std::env::temp_dir().join(format!("bytesize-guard-test-{}", std::process::id()));
|
||||
let scratch = dir.join("temp").join("ffmpeg-extract");
|
||||
drop(fs::remove_dir_all(&dir));
|
||||
|
||||
assert!(fails_with_guard_alive(&scratch).is_err());
|
||||
assert!(
|
||||
!scratch.exists(),
|
||||
"scratch dir should be gone after the error return"
|
||||
);
|
||||
|
||||
drop(fs::remove_dir_all(&dir));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user