fix extraction leak, dead deps, logging, and frontend races
This commit is contained in:
+34
-16
@@ -266,27 +266,45 @@ fn is_ffmpeg_entry(name: &str) -> bool {
|
||||
}
|
||||
|
||||
fn extract_ffmpeg_from_7z(archive: &[u8], dest: &Path) -> Result<()> {
|
||||
let app_dir = dest
|
||||
.parent()
|
||||
.and_then(|p| p.parent())
|
||||
.context("invalid dest path")?;
|
||||
let scratch = app_dir.join("temp").join("ffmpeg-extract");
|
||||
let _ = fs::remove_dir_all(&scratch);
|
||||
fs::create_dir_all(&scratch).context("create 7z scratch dir")?;
|
||||
|
||||
let reader = Cursor::new(archive);
|
||||
let mut extracted = false;
|
||||
let scratch = std::env::temp_dir();
|
||||
sevenz_rust2::decompress_with_extract_fn(reader, scratch, |entry, src, _| {
|
||||
if extracted || entry.is_directory() {
|
||||
return Ok(true);
|
||||
}
|
||||
if is_ffmpeg_entry(entry.name()) {
|
||||
let mut out = File::create(dest)?;
|
||||
io::copy(src, &mut out)?;
|
||||
extracted = true;
|
||||
}
|
||||
Ok(true)
|
||||
})
|
||||
.map_err(|e| anyhow!("7z extraction failed: {e}"))?;
|
||||
if !extracted {
|
||||
let extract_result = sevenz_rust2::decompress_with_extract_fn(reader, &scratch, |_, _, _| Ok(true))
|
||||
.map_err(|e| anyhow!("7z extraction failed: {e}"));
|
||||
let found = find_ffmpeg_in(&scratch);
|
||||
let _ = fs::remove_dir_all(&scratch);
|
||||
|
||||
extract_result?;
|
||||
let Some(src) = found else {
|
||||
bail!("ffmpeg.exe not found inside the 7z archive");
|
||||
}
|
||||
};
|
||||
fs::copy(&src, dest).context("write ffmpeg.exe from 7z")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn find_ffmpeg_in(dir: &Path) -> Option<PathBuf> {
|
||||
let entries = fs::read_dir(dir).ok()?;
|
||||
for e in entries.flatten() {
|
||||
let p = e.path();
|
||||
if p.is_dir() {
|
||||
if let Some(found) = find_ffmpeg_in(&p) {
|
||||
return Some(found);
|
||||
}
|
||||
} else if let Some(name) = p.file_name() {
|
||||
if is_ffmpeg_entry(&name.to_string_lossy()) {
|
||||
return Some(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn extract_ffmpeg_from_zip(archive: &[u8], dest: &Path) -> Result<()> {
|
||||
let reader = Cursor::new(archive);
|
||||
let mut zip = zip::ZipArchive::new(reader).context("open zip archive")?;
|
||||
|
||||
Reference in New Issue
Block a user