From b1276adf59e5a57987fc31361069585630f27c85 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 06:20:01 -0800 Subject: [PATCH] Package: a canceled save before packaging writes no package With Background Save and Background Export on, a package waits for the document's save and started once that save answered without an error, so a save that Cancel Save stopped still let the package be written from a document left unsaved. A canceled save now stops the package, as a failed one does. --- crates/ui-egui/src/dialogs/package.rs | 6 +++--- crates/ui-egui/src/dialogs/tests_package.rs | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs/package.rs b/crates/ui-egui/src/dialogs/package.rs index 25d17d3902..3e69af017c 100644 --- a/crates/ui-egui/src/dialogs/package.rs +++ b/crates/ui-egui/src/dialogs/package.rs @@ -173,10 +173,10 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { Ok(r) } -/// Did a save whose applied result is `r` write the document (no error, and no question asked -/// before writing)? +/// Did a save whose applied result is `r` write the document (no error, no question asked before +/// writing, and not canceled by Cancel Save)? fn saved(r: &Result) -> bool { - r.as_ref().is_ok_and(|r| r.get("pending").is_none()) + r.as_ref().is_ok_and(|r| r.get("pending").is_none() && r.get("cancelled").and_then(Value::as_bool) != Some(true)) } /// Report the package `r` (`file.package`'s reply): the status bar, the web's download, and the diff --git a/crates/ui-egui/src/dialogs/tests_package.rs b/crates/ui-egui/src/dialogs/tests_package.rs index 0c0f8e492a..e89e5501f5 100644 --- a/crates/ui-egui/src/dialogs/tests_package.rs +++ b/crates/ui-egui/src/dialogs/tests_package.rs @@ -280,6 +280,27 @@ fn a_failed_save_before_packaging_writes_no_package() { } } +/// A save before packaging that Cancel Save stops writes no package either: the document keeps +/// its unsaved changes, so the package would not hold it as saved. +#[test] +fn a_canceled_save_before_packaging_writes_no_package() { + let dir = Folder::new("canceled-save"); + let gate = Gate::default(); + let (mut app, files) = saved_with_worker(&dir, &gate); + let out = dir.path("out"); + // An export holds the worker, so the save waits behind it and Cancel comes before it starts. + crate::io::export(&mut app, Some("svg"), Some(dir.path("first.svg")), &json!({})).unwrap(); + app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap(); + package_dialog(&mut app, &out); + assert_eq!(confirm(&mut app).unwrap()["background"], true); + assert_eq!(app.run("file.cancelSave", json!({})).unwrap()["cancelled"], 1); + gate.open(); + background::wait_all(&mut app); + assert_eq!(written(&files), [dir.path("first.svg")], "only the export"); + assert!(!std::path::Path::new(&out).join("card Folder").exists(), "no package folder"); + assert!(app.session.active().unwrap().is_dirty(), "the save was canceled"); +} + /// A package that an automation request confined to its roots asks for, started once the /// document's background save is written, is still confined to those roots, though the save's /// result arrives outside the request.