extract the d3d descriptors and cover the sweep and guard paths

This commit is contained in:
2026-09-21 02:10:52 +03:00
parent 930d67fdd6
commit c9ee532bd3
4 changed files with 170 additions and 94 deletions
+32
View File
@@ -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));
}
}