LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge main into fix/symlink-original-guard
Brandon Thomas1ce28c3aeac9
diff --cc crates/engine/src/tests_export.rsindex 422601338,1515d7bf6..faba3e3c1--- a/crates/engine/src/tests_export.rs+++ b/crates/engine/src/tests_export.rs@@@ -324,28 -324,23 +324,49 @@@ fn a_failed_export_write_keeps_the_prevlet _ = std::fs::remove_dir_all(&dir);}+#[cfg(unix)]+#[test]+fn export_protects_the_target_of_an_imported_symlink() {+ use crate::export::{Conflict, Destination};+ let (original_session, _, dir, src, original) = library_with_jpeg("export-symlink-original");+ drop(original_session);+ let alias = dir.join("alias.jpg");+ std::os::unix::fs::symlink(&src, &alias).unwrap();+ let sidecar = dir.join("metadata.xmp");+ std::fs::write(&sidecar, b"<x/>").unwrap();+ std::os::unix::fs::symlink(&sidecar, alias.with_extension("xmp")).unwrap();+ let mut s = Session::new().with_fs();+ s.execute("library.import", &json!({"paths": [alias.to_string_lossy()]})).unwrap();+ let id = s.catalog.photos().next().unwrap().id;+ s.execute("develop.set", &json!({"ids": [id.0], "control": "light.exposure", "value": 1.0})).unwrap();+ let o = ExportOptions { conflict: Conflict::Overwrite, ..Default::default() };+ let to = Destination { dir: String::new(), exact: Some(src.to_string_lossy().to_string()) };+ let result = disk_batch(&mut s, id, &o, &to);+ assert!(result.is_err(), "export replaced the original through its imported alias: {result:?}");+ assert_eq!(std::fs::read(&src).unwrap(), original);+ assert!(s.execute("export.checkTarget", &json!({"path": src.to_string_lossy()})).is_err());+ assert!(s.execute("export.checkTarget", &json!({"path": sidecar.to_string_lossy()})).is_err());+ assert_eq!(std::fs::read(&sidecar).unwrap(), b"<x/>");+ let _ = std::fs::remove_dir_all(&dir);+}+++ /// Issue #134: exports can always be made again, so they are written atomically but not synced to+ /// disk file by file; an edit copy that becomes a library photo still is.+ #[test]+ fn exports_are_atomic_without_a_sync() {+ use crate::export::{Conflict, Destination};+ use lightcraft_catalog::safe_file::syncs_on_this_thread;+ let (mut s, id, dir, _src, _) = library_with_jpeg("export-nosync");+ let out = dir.join("out");+ let to = Destination { dir: out.to_string_lossy().to_string(), exact: None };+ let o = ExportOptions { conflict: Conflict::Unique, ..Default::default() };+ let before = syncs_on_this_thread();+ for _ in 0..3 {+ disk_batch(&mut s, id, &o, &to).unwrap();+ }+ assert_eq!(syncs_on_this_thread(), before, "no per-file sync for exports");+ assert_eq!(std::fs::read_dir(&out).unwrap().count(), 3, "three exports, no temp files");+ crate::export::write_file_durable(&out.join("edit.tif").to_string_lossy(), b"tiff").unwrap();+ assert!(syncs_on_this_thread() > before, "the durable writer syncs");+ let _ = std::fs::remove_dir_all(&dir);+ }