Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge remote-tracking branch 'origin/main' into fix/bundle-save-lock

Finn Newickd770fd35f106
diff --cc crates/format/tests/roundtrip.rs
index b4c04d6db,f78e93947..3f3275589
--- a/crates/format/tests/roundtrip.rs
+++ b/crates/format/tests/roundtrip.rs
@@@ -730,24 -730,24 +730,46 @@@ fn a_non_finite_float_is_refused_at_sav
assert_eq!(back, doc);
}
+/// #4957: a directory save holds the bundle's lock for its whole transaction. While another
+/// writer holds it, a save waits, then fails without writing anything; once it is released the
+/// save goes ahead.
+#[test]
+fn directory_save_waits_for_the_bundle_lock() {
+ let doc = rich_doc(ColorMode::Rgb, SampleType::U8);
+ let dir = temp_dir("lock");
+ let other = std::fs::OpenOptions::new().read(true).write(true).create(true).truncate(false).open(dir.join("save.lock")).unwrap();
+ other.lock().unwrap();
+ let mut w = PcraftWriter::new();
+ w.set_lock_wait(std::time::Duration::from_millis(100));
+ let e = w.save_dir(&doc, &dir, &SaveOptions::default()).unwrap_err();
+ assert!(e.to_string().contains("in progress"), "{e}");
+ assert!(!dir.join("manifest.json").exists(), "nothing written while locked");
+ assert!(!dir.join("tiles").exists() || std::fs::read_dir(dir.join("tiles")).unwrap().count() == 0);
+ other.unlock().unwrap();
+ w.save_dir(&doc, &dir, &SaveOptions::default()).unwrap();
+ assert_eq!(load_path(&dir).unwrap(), doc);
+ drop(other);
+ std::fs::remove_dir_all(dir).unwrap();
+}
++
+ #[test]
+ fn variables_follow_layer_id_remapping() {
+ let mut doc = rich_doc(ColorMode::Rgb, SampleType::U8);
+ let id_of = |d: &Document, name: &str| d.walk().into_iter().find(|(_, _, l)| l.name == name).unwrap().2.id;
+ doc.variables.defs = vec![
+ VariableDef { name: "head".into(), layer: id_of(&doc, "Paint"), kind: VarKind::TextReplacement },
+ VariableDef { name: "badge".into(), layer: id_of(&doc, "Inner"), kind: VarKind::Visibility },
+ VariableDef { name: "gone".into(), layer: LayerId(u64::MAX), kind: VarKind::Visibility },
+ ];
+ let bytes = save_to_bytes(&doc, &SaveOptions::default()).unwrap();
+ // Preserved ids keep every definition exactly as saved, dangling ones included.
+ assert_eq!(load_from_bytes(&bytes).unwrap(), doc);
+ // Remapped ids carry the definitions to the copied layers; a dangling target stays
+ // dangling and must not collide with a live layer (#4969).
+ let back = load_from_bytes_with(&bytes, &LoadOptions { preserve_ids: false, ..Default::default() }).unwrap();
+ let defs = &back.variables.defs;
+ assert_eq!(defs.iter().find(|d| d.name == "head").unwrap().layer, id_of(&back, "Paint"));
+ assert_eq!(defs.iter().find(|d| d.name == "badge").unwrap().layer, id_of(&back, "Inner"));
+ let gone = defs.iter().find(|d| d.name == "gone").unwrap().layer;
+ assert!(back.walk().into_iter().all(|(_, _, l)| l.id != gone), "dangling target must not address a live layer");
+ }