keep temp clean and previews alive across a capture
This commit is contained in:
@@ -287,6 +287,16 @@ fn is_ffmpeg_entry(name: &str) -> bool {
|
||||
.is_some_and(|leaf| leaf.eq_ignore_ascii_case("ffmpeg.exe"))
|
||||
}
|
||||
|
||||
/// Removes a scratch directory on drop so extraction failures don't leave an
|
||||
/// unpacked ffmpeg build sitting in temp/.
|
||||
struct DirGuard(PathBuf);
|
||||
|
||||
impl Drop for DirGuard {
|
||||
fn drop(&mut self) {
|
||||
drop(fs::remove_dir_all(&self.0));
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_ffmpeg_from_7z(archive_path: &Path, dest: &Path) -> Result<()> {
|
||||
let app_dir = dest
|
||||
.parent()
|
||||
@@ -295,13 +305,16 @@ fn extract_ffmpeg_from_7z(archive_path: &Path, dest: &Path) -> Result<()> {
|
||||
let scratch = app_dir.join("temp").join("ffmpeg-extract");
|
||||
drop(fs::remove_dir_all(&scratch));
|
||||
fs::create_dir_all(&scratch).context("create 7z scratch dir")?;
|
||||
// Removes the extracted tree on every exit path, including the extraction
|
||||
// failure below - the older unconditional remove sat before the `?`, so a
|
||||
// failed extract left the whole unpacked build behind in temp/.
|
||||
let _guard = DirGuard(scratch.clone());
|
||||
|
||||
let file = File::open(archive_path).context("opening 7z archive")?;
|
||||
let extract_result =
|
||||
sevenz_rust2::decompress_with_extract_fn(file, &scratch, |_, _, _| Ok(true))
|
||||
.map_err(|e| anyhow!("7z extraction failed: {e}"));
|
||||
let found = find_ffmpeg_in(&scratch);
|
||||
drop(fs::remove_dir_all(&scratch));
|
||||
|
||||
extract_result?;
|
||||
let Some(src) = found else {
|
||||
|
||||
Reference in New Issue
Block a user