mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Address CodeRabbit review: a cancel after an action's saved snapshot keeps that file
When an action saves and then closes or switches away, Batch writes the saved snapshot inside the action closure. A cancel landing after that write made process_one return Cancelled, so the input was reported as skipped although its output exists. The snapshot write is now final: the cancel stops only the inputs after it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
559d3fe0f4
commit
ae0da189a2
2 files changed
+35
-10
No files matched your search
@@ -221,24 +221,27 @@ fn process_one(raw_ppi: f64, path: &str, out: &str, save: SaveOpts, options: Pro
|
||||
ctx.publish_batch_preview(path, scratch.active().map(|state| state.doc.clone()));
|
||||
}
|
||||
let saved_by_action = f(&mut scratch, out)?;
|
||||
if saved_by_action {
|
||||
// The action's saved snapshot is already written: a cancel or Esc arriving now stops the
|
||||
// inputs after this one, not this result.
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(ctx) = options.ctx {
|
||||
ctx.check()?;
|
||||
if ctx.batch_interrupt_requested() {
|
||||
return Err(EngineError::Cancelled);
|
||||
}
|
||||
}
|
||||
if !saved_by_action {
|
||||
let d = scratch.active().ok_or(EngineError::NoDocument)?;
|
||||
if let Some(format) = options.format {
|
||||
let ext = if format == "same" { same_format(path) } else { format.trim_start_matches('.').to_ascii_lowercase() };
|
||||
if let Some(ctx) = options.ctx {
|
||||
save_batch_doc(&d.doc, out, &ext, save, ctx)?;
|
||||
} else {
|
||||
save_doc_as(&d.doc, out, &ext, save)?;
|
||||
}
|
||||
let d = scratch.active().ok_or(EngineError::NoDocument)?;
|
||||
if let Some(format) = options.format {
|
||||
let ext = if format == "same" { same_format(path) } else { format.trim_start_matches('.').to_ascii_lowercase() };
|
||||
if let Some(ctx) = options.ctx {
|
||||
save_batch_doc(&d.doc, out, &ext, save, ctx)?;
|
||||
} else {
|
||||
save_doc(&d.doc, out, save)?;
|
||||
save_doc_as(&d.doc, out, &ext, save)?;
|
||||
}
|
||||
} else {
|
||||
save_doc(&d.doc, out, save)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -89,6 +89,28 @@ fn batch_cancelled_during_an_action_does_not_save_that_input() {
|
||||
assert!(!std::path::Path::new(&out).exists());
|
||||
}
|
||||
|
||||
/// An action that saved and then closed its document has its saved snapshot written by the time
|
||||
/// it returns: a cancel landing then counts that file as written, not skipped.
|
||||
#[test]
|
||||
fn batch_cancel_after_a_saved_snapshot_is_written_keeps_that_file() {
|
||||
let dir = tmp("batch-cancel-after-snapshot");
|
||||
let first = png(&dir, "first.png", 8, 6, "#ff0000");
|
||||
let second = png(&dir, "second.png", 8, 6, "#00ff00");
|
||||
let first_out = join(&dir, "out/first.png");
|
||||
let ctx = crate::jobs::JobCtx::new();
|
||||
let policy = super::batch_run::BatchPolicy { stop_on_error: false, error_log: None };
|
||||
let outputs = vec![(first, first_out.clone()), (second.clone(), join(&dir, "out/second.png"))];
|
||||
let result = super::batch_run::process_batch_outputs(72.0, outputs, "png", SaveOpts::default(), &policy, &ctx, &|s, out| {
|
||||
save_doc(&s.active().unwrap().doc, out, None).unwrap();
|
||||
ctx.cancel();
|
||||
Ok(true)
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(result["files"], json!([first_out]), "{result}");
|
||||
assert_eq!(result["skipped"], json!([second]), "{result}");
|
||||
assert_eq!(result["cancelled"], json!(true), "{result}");
|
||||
}
|
||||
|
||||
/// A cancel that lands while an input fails on its own keeps that failure and its reason; only
|
||||
/// the inputs after it are skipped.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user