From ec68dccf3379363bd31d1b729730fc7e27bfec18 Mon Sep 17 00:00:00 2001 From: Wes Date: Fri, 21 Aug 2026 18:32:57 -0600 Subject: [PATCH] fix(desktop): clean staged avconvert inputs Remove partial staged sources when a fallback copy fails, and honor cancellation before starting AVFoundation conversion. Co-authored-by: Wes Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz> Signed-off-by: Wes --- desktop/src-tauri/src/commands/media_transcode.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/desktop/src-tauri/src/commands/media_transcode.rs b/desktop/src-tauri/src/commands/media_transcode.rs index 601529a3e1..7e878ad5dd 100644 --- a/desktop/src-tauri/src/commands/media_transcode.rs +++ b/desktop/src-tauri/src/commands/media_transcode.rs @@ -478,7 +478,10 @@ fn prepare_avconvert_source( )); if std::fs::hard_link(source, &staged).is_err() { std::fs::copy(source, &staged) - .map_err(|error| format!("failed to stage video for conversion: {error}"))?; + .map_err(|error| format!("failed to stage video for conversion: {error}")) + .inspect_err(|_| { + let _ = std::fs::remove_file(&staged); + })?; } Ok((staged, true)) } @@ -495,6 +498,12 @@ fn transcode_with_avconvert( ) -> Result, String> { let output = std::env::temp_dir().join(format!("buzz-avconvert-{}.mp4", uuid::Uuid::new_v4())); let (prepared_source, remove_prepared_source) = prepare_avconvert_source(source)?; + if cancellation.is_some_and(CancellationToken::is_cancelled) { + if remove_prepared_source { + let _ = std::fs::remove_file(&prepared_source); + } + return Err("upload cancelled".to_string()); + } let result = (|| { let mut command = std::process::Command::new("/usr/bin/avconvert");