Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(export): stop GIF exports when staging fails
Aditya Garud850dd91c06f2
diff --git a/crates/export/src/gif.rs b/crates/export/src/gif.rsindex fcc473c12..27439e6c2 100644--- a/crates/export/src/gif.rs+++ b/crates/export/src/gif.rs@@ -109,7 +109,7 @@ impl GifExportSettings {}).unwrap_or_default();- let temporary_output = prepare_new_output(&gif_output_path);+ let temporary_output = prepare_new_output(&gif_output_path)?;let mut gif_encoder = cap_enc_gif::GifEncoderWrapper::new_with_quality(temporary_output.as_ref()diff --git a/crates/export/src/lib.rs b/crates/export/src/lib.rsindex a2b5be57f..a3c9b7420 100644--- a/crates/export/src/lib.rs+++ b/crates/export/src/lib.rs@@ -360,17 +360,19 @@ fn prepare_streaming_output(if !eligible || output.extension().and_then(|extension| extension.to_str()) != Some("mp4") {return None;}- prepare_new_output(output)+ prepare_new_output(output).ok().flatten()}/// Stages a new export beside its destination so a failed or cancelled export/// never leaves a partial file there. Existing destinations are written in place.-fn prepare_new_output(output: &std::path::Path) -> Option<mp4::TemporaryExportOutput> {+fn prepare_new_output(+ output: &std::path::Path,+) -> Result<Option<mp4::TemporaryExportOutput>, String> {if !matches!(std::fs::symlink_metadata(output), Err(error) if error.kind() == std::io::ErrorKind::NotFound){- return None;+ return Ok(None);}- mp4::temporary_export_output(output).ok()+ mp4::temporary_export_output(output).map(Some)}struct ExportAudioCancellation {@@ -640,6 +642,23 @@ mod cancellation_tests {assert_eq!(std::fs::read(existing).unwrap(), b"existing");}+ #[test]+ fn new_gif_destinations_are_staged_beside_the_output() {+ let directory = tempfile::tempdir().unwrap();+ let output = directory.path().join("export.gif");+ let staged = prepare_new_output(&output).unwrap().unwrap();+ let staged_path = staged.to_path_buf();+ assert_eq!(staged_path.parent(), Some(directory.path()));+ assert_eq!(staged_path.extension(), output.extension());+ assert!(!output.exists());+ staged.persist_noclobber(&output).unwrap();+ assert!(output.exists());+ assert!(!staged_path.exists());++ assert!(prepare_new_output(&output).unwrap().is_none());+ assert!(prepare_new_output(&directory.path().join("missing/export.gif")).is_err());+ }+#[test]fn prepared_destination_is_removed_when_preparation_is_dropped() {let directory = tempfile::tempdir().unwrap();