diff --git a/Cargo.lock b/Cargo.lock index 37233ef58..66597f96e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1592,6 +1592,7 @@ dependencies = [ "image", "log", "rayon", + "tempfile", "thiserror 2.0.21", "web-time", ] diff --git a/crates/export/Cargo.toml b/crates/export/Cargo.toml index c477d2787..e0be45551 100644 --- a/crates/export/Cargo.toml +++ b/crates/export/Cargo.toml @@ -31,6 +31,7 @@ thiserror = { workspace = true } log = { workspace = true } [dev-dependencies] +tempfile = { workspace = true } effectcraft-media = { workspace = true } effectcraft-effects = { workspace = true } effectcraft-color = { workspace = true } diff --git a/crates/export/src/lib.rs b/crates/export/src/lib.rs index 48cb07ac4..a5a39e8b3 100644 --- a/crates/export/src/lib.rs +++ b/crates/export/src/lib.rs @@ -329,7 +329,12 @@ async fn sequence(cx: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut State<'_>) let mut buf = std::io::Cursor::new(Vec::new()); write_still(cx, &mut buf, &img, comp, StillOutput { format: fmt, channels, size: (w, h), quality: cx.output.quality })?; let data = buf.into_inner(); - let path = cx.place(&path, data.len() as u64); + let primary = path; + let path = cx.place(&primary, data.len() as u64); + // Skip Existing also protects a frame already in the overflow folder. + if cx.settings.skip_existing && path != primary && out::exists(cx.sink, &path) { + return Ok(0); + } let mut f = cx.create(&path)?; std::io::Write::write_all(&mut f, &data).map_err(io)?; f.finish() diff --git a/crates/export/tests/it/render_settings.rs b/crates/export/tests/it/render_settings.rs index 39a7e88ff..b67d8466f 100644 --- a/crates/export/tests/it/render_settings.rs +++ b/crates/export/tests/it/render_settings.rs @@ -444,6 +444,45 @@ fn cancelled_export_removes_only_files_it_opened() { std::fs::remove_dir_all(dir).unwrap(); } +/// Skip Existing keeps a frame that is already in the overflow folder the frame is placed in +/// (it checked only the primary destination, then truncated the overflow file). +#[test] +fn skip_existing_keeps_a_frame_in_the_overflow_folder() { + struct Overflow; + impl StorageQuota for Overflow { + fn has_room(&self, path: &str, _: u64) -> bool { + path.contains("overflow") + } + } + let guard = tempfile::tempdir().unwrap(); + let (dir, over) = (guard.path().to_path_buf(), guard.path().join("overflow")); + std::fs::create_dir_all(&over).unwrap(); + std::fs::write(over.join("clip_00000.png"), b"keep").unwrap(); + let (p, cid) = project(FrameRate::new(25, 1), |_, _| {}); + let settings = RenderSettings { skip_existing: true, storage_overflow: true, ..Default::default() }; + let om = OutputModule::for_format(OutputFormat::PngSequence); + let path = dir.join("clip_[#####].png"); + let result = export( + &Job { + project: &p, + footage: &NoFootage, + expr: None, + accel: None, + comp: cid, + settings: &settings, + output: &om, + path: path.to_str().unwrap(), + sink: None, + nested_switches: true, + options: JobOptions { storage: Some(&Overflow), overflow: vec![over.to_string_lossy().into_owned()], ..Default::default() }, + }, + &mut |_| true, + ); + assert!(result.is_ok(), "{result:?}"); + assert_eq!(std::fs::read(over.join("clip_00000.png")).unwrap(), b"keep"); + assert!(over.join("clip_00001.png").exists(), "the other frames are still written"); +} + /// A GPU compositor stand-in that renders every frame solid green (the CPU draws the bar and the /// block on black) and keeps Auto's timing history. #[derive(Default)]