From eae7dcd2069cdddf38a60a400f9ccbc083134a83 Mon Sep 17 00:00:00 2001 From: Andrew Frahn Date: Mon, 26 Oct 2026 11:22:30 +1100 Subject: [PATCH 1/4] LRC-LIB-LIBFOLDERS: a date folder inside the library can be renamed folder.rename / folder.move refused any folder below the library folder (`src.starts_with(&l.dir)`), so the date folders an import copies into `Originals/` could never be renamed. Only the library folder, its parents and its own top-level folders (`Originals`, `thumbs`) are refused now. A refused Rename Folder prompt also closed silently; it now shows why in a toast, as Move Photos does. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/browse.rs | 4 +++- crates/engine/src/tests_folders.rs | 24 ++++++++++++++++++++++++ crates/ui-egui/src/panels/dialogs.rs | 3 ++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/browse.rs b/crates/engine/src/cmd/browse.rs index 6f3f889631..eace5943ad 100644 --- a/crates/engine/src/cmd/browse.rs +++ b/crates/engine/src/cmd/browse.rs @@ -513,7 +513,9 @@ pub(crate) fn move_folder(s: &mut Session, from: &str, to: &str) -> std::result: if !src.is_dir() { return Err(format!("{from} is not a folder")); } - if s.library.as_ref().is_some_and(|l| l.dir.starts_with(src) || src.starts_with(&l.dir)) { + // the library folder itself, and its own top-level folders (`Originals`, `thumbs`), stay where + // the library expects them; folders below those (an import's date folders) can be renamed + if s.library.as_ref().is_some_and(|l| l.dir.starts_with(src) || src.parent() == Some(l.dir.as_path())) { return Err("the library's own folders can't be moved here".into()); } // Repairs retain their exact old paths, including those on surviving history entries. diff --git a/crates/engine/src/tests_folders.rs b/crates/engine/src/tests_folders.rs index 34017fc977..739ccecd91 100644 --- a/crates/engine/src/tests_folders.rs +++ b/crates/engine/src/tests_folders.rs @@ -16,6 +16,7 @@ use lightcraft_catalog::{Op, Photo, Source}; use serde_json::json; +use std::path::Path; use crate::{LibrarySource, Session, filter_chips}; @@ -701,3 +702,26 @@ fn a_destination_without_write_permission_reports_an_error_and_keeps_everything( } std::fs::set_permissions(dir.0.join("ro"), std::fs::Permissions::from_mode(0o755)).unwrap(); } + +#[test] +fn a_date_folder_inside_the_library_can_be_renamed_but_the_librarys_own_folders_cannot() { + let dir = Scratch::new("in-library"); + let lib = dir.0.join("lib"); + let mut s = Session::new(); + s.open_library(&lib, false).unwrap(); + let day = lib.join("Originals").join("2026-10-16"); + std::fs::create_dir_all(&day).unwrap(); + add(&mut s, &day.join("a.jpg").to_string_lossy()); + let day = day.to_string_lossy().to_string(); + s.execute("folder.rename", &json!({"path": day, "name": "Beach"})).unwrap(); + assert!(lib.join("Originals/Beach").is_dir(), "the imported date folder is renamed"); + assert!(!Path::new(&day).exists()); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(Path::new(&day).is_dir(), "undo names it back"); + for own in ["Originals", "thumbs"] { + std::fs::create_dir_all(lib.join(own)).unwrap(); + let path = lib.join(own).to_string_lossy().to_string(); + assert!(s.execute("folder.rename", &json!({"path": path, "name": "x"})).is_err(), "{own} stays put"); + } + assert!(s.execute("folder.rename", &json!({"path": lib.to_string_lossy(), "name": "x"})).is_err(), "and so does the library"); +} diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs index f26b433255..925d482269 100644 --- a/crates/ui-egui/src/panels/dialogs.rs +++ b/crates/ui-egui/src/panels/dialogs.rs @@ -1581,7 +1581,8 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context, blocked: bool) { } close = true; } - Err(e) if matches!(dlg, Dialog::MovePhotos { .. }) => { + // a prompt (Rename Folder, …) that is refused closes and says why + Err(e) if matches!(dlg, Dialog::MovePhotos { .. } | Dialog::TextPrompt { .. }) => { app.toast(ctx, e); close = true; } From 90b3e0489b3684fdda3636ef2a91e4ba8fdda0fb Mon Sep 17 00:00:00 2001 From: Andrew Frahn Date: Mon, 26 Oct 2026 11:43:37 +1100 Subject: [PATCH 2/4] LRC-LIB-LIBFOLDERS: a folder path with '..' is refused before the library check Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/browse.rs | 4 ++++ crates/engine/src/tests_folders.rs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/crates/engine/src/cmd/browse.rs b/crates/engine/src/cmd/browse.rs index eace5943ad..83478cbdb1 100644 --- a/crates/engine/src/cmd/browse.rs +++ b/crates/engine/src/cmd/browse.rs @@ -513,6 +513,10 @@ pub(crate) fn move_folder(s: &mut Session, from: &str, to: &str) -> std::result: if !src.is_dir() { return Err(format!("{from} is not a folder")); } + // `a/../b` names a folder without spelling it, which the checks below and the relink can't see + if src.components().any(|c| matches!(c, std::path::Component::ParentDir)) { + return Err(format!("{from}: give the folder's path without '..'")); + } // the library folder itself, and its own top-level folders (`Originals`, `thumbs`), stay where // the library expects them; folders below those (an import's date folders) can be renamed if s.library.as_ref().is_some_and(|l| l.dir.starts_with(src) || src.parent() == Some(l.dir.as_path())) { diff --git a/crates/engine/src/tests_folders.rs b/crates/engine/src/tests_folders.rs index 739ccecd91..f2269443be 100644 --- a/crates/engine/src/tests_folders.rs +++ b/crates/engine/src/tests_folders.rs @@ -724,4 +724,7 @@ fn a_date_folder_inside_the_library_can_be_renamed_but_the_librarys_own_folders_ assert!(s.execute("folder.rename", &json!({"path": path, "name": "x"})).is_err(), "{own} stays put"); } assert!(s.execute("folder.rename", &json!({"path": lib.to_string_lossy(), "name": "x"})).is_err(), "and so does the library"); + let alias = lib.join("Originals").join("..").join("Originals").to_string_lossy().to_string(); + assert!(s.execute("folder.rename", &json!({"path": alias, "name": "x"})).is_err(), "even named through '..'"); + assert!(lib.join("Originals").is_dir()); } From 6cee4f2632d5244f4cc52480cd7d8c0e7ae2118f Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:34:53 +0700 Subject: [PATCH 3/4] Refuse a library folder named through a link; keep a refused prompt open as main does - folder.rename/folder.move: a folder inside the library reached through a link to the library (or another spelling of its path) moved on disk while its photos, stored under the library's own path, kept pointing at the old folder. It is now refused with the path to use, and a regression test covers the linked parent (CodeRabbit). - dialogs: the TextPrompt pattern added to the MovePhotos error arm could never match, since the earlier TextPrompt arm from 17a9e97a (a refused one-line prompt stays open with its text so the name can be fixed) wins. Drop it so the code says what runs (CodeRabbit). --- crates/engine/src/cmd/browse.rs | 8 ++++++++ crates/engine/src/tests/folders.rs | 29 +++++++++++++++++++++++++++++ crates/ui-egui/src/dialogs.rs | 3 +-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/browse.rs b/crates/engine/src/cmd/browse.rs index 730782469a..feb513636e 100644 --- a/crates/engine/src/cmd/browse.rs +++ b/crates/engine/src/cmd/browse.rs @@ -537,6 +537,14 @@ pub(crate) fn move_folder(s: &mut Session, from: &str, to: &str) -> std::result: if s.library.as_ref().is_some_and(|l| same_folder(&l.dir)) { return Err("the library's own folders can't be moved here".into()); } + // a folder inside the library reached through a link (or another spelling of the library's path) would move on + // disk, but its photos are stored under the library's own spelling, so the relink below couldn't find them + if let Some(l) = s.library.as_ref() { + let (lib, chosen) = (l.dir.canonicalize().unwrap_or_else(|_| l.dir.clone()), src.canonicalize().unwrap_or_else(|_| src.to_path_buf())); + if chosen.starts_with(&lib) && !src.starts_with(&l.dir) { + return Err(format!("{from}: give the folder's path inside the library as {}", l.dir.display())); + } + } // Repairs retain their exact old paths, including those on surviving history entries. // Complete them before the directory moves; an unavailable repair leaves it in place. s.repair_sidecars_with(&crate::rename::RealFs).map_err(|e| e.to_string())?; diff --git a/crates/engine/src/tests/folders.rs b/crates/engine/src/tests/folders.rs index 68a918093b..ff04b85201 100644 --- a/crates/engine/src/tests/folders.rs +++ b/crates/engine/src/tests/folders.rs @@ -729,6 +729,35 @@ fn a_date_folder_inside_the_library_can_be_renamed_but_the_librarys_own_folders_ assert!(lib.join("Originals").is_dir()); } +/// A date folder inside the library named through a link to the library would move on disk while its photos, +/// stored under the library's own path, kept pointing at the old folder: it is refused and nothing moves. +#[cfg(unix)] +#[test] +fn a_folder_inside_the_library_named_through_a_link_is_refused_and_its_photos_keep_their_paths() { + let dir = Scratch::new("in-library-link"); + let lib = dir.0.join("lib"); + let mut s = Session::new(); + s.open_library(&lib, false).unwrap(); + let day = lib.join("Originals").join("2026-10-16"); + std::fs::create_dir_all(&day).unwrap(); + let photo = day.join("a.jpg").to_string_lossy().to_string(); + std::fs::write(&photo, b"jpeg").unwrap(); + add(&mut s, &photo); + std::os::unix::fs::symlink(&lib, dir.0.join("lib-link")).unwrap(); + let linked = dir.0.join("lib-link").join("Originals").join("2026-10-16").to_string_lossy().to_string(); + assert!(s.execute("folder.rename", &json!({"path": linked, "name": "Beach"})).is_err(), "a linked spelling is refused"); + assert!(day.is_dir() && !lib.join("Originals/Beach").exists(), "nothing moved on disk"); + let paths: Vec<_> = s + .catalog + .photos() + .filter_map(|p| match &p.source { + Source::File { path } => Some(path.clone()), + _ => None, + }) + .collect(); + assert!(paths.iter().all(|p| Path::new(p).exists()), "every photo still points at a file: {paths:?}"); +} + #[cfg(unix)] #[test] fn the_library_folder_is_protected_however_its_path_is_spelled() { diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 4d344a44e4..e762ba7371 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -773,8 +773,7 @@ fn confirmed(app: &mut LightcraftApp, ctx: &egui::Context, dlg: &mut Dialog) -> } closed = true; } - // a prompt (Rename Folder, …) that is refused closes and says why - Err(e) if matches!(dlg, Dialog::MovePhotos { .. } | Dialog::TextPrompt { .. }) => { + Err(e) if matches!(dlg, Dialog::MovePhotos { .. }) => { app.toast(ctx, e); closed = true; } From f3019601485f3743d961a9cc9fd937171240bfd6 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Thu, 26 Nov 2026 20:01:54 +0700 Subject: [PATCH 4/4] Test: a renamed date folder in the library relinks its photo, and undo points it back The test registered a photo whose file didn't exist and never checked the relink. It now writes the file, checks `relinked`, the photo's catalog path and the file after the rename, and both again after the one undo step (CodeRabbit). --- crates/engine/src/tests/folders.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests/folders.rs b/crates/engine/src/tests/folders.rs index ff04b85201..1acabb6bd3 100644 --- a/crates/engine/src/tests/folders.rs +++ b/crates/engine/src/tests/folders.rs @@ -711,13 +711,30 @@ fn a_date_folder_inside_the_library_can_be_renamed_but_the_librarys_own_folders_ s.open_library(&lib, false).unwrap(); let day = lib.join("Originals").join("2026-10-16"); std::fs::create_dir_all(&day).unwrap(); - add(&mut s, &day.join("a.jpg").to_string_lossy()); + let photo = day.join("a.jpg"); + std::fs::write(&photo, b"jpeg").unwrap(); + add(&mut s, &photo.to_string_lossy()); + let paths = |s: &Session| -> Vec { + s.catalog + .photos() + .filter_map(|p| match &p.source { + Source::File { path } => Some(path.clone()), + _ => None, + }) + .collect() + }; let day = day.to_string_lossy().to_string(); - s.execute("folder.rename", &json!({"path": day, "name": "Beach"})).unwrap(); + let r = s.execute("folder.rename", &json!({"path": day, "name": "Beach"})).unwrap(); + assert_eq!(r["relinked"], 1, "the photo inside is relinked"); assert!(lib.join("Originals/Beach").is_dir(), "the imported date folder is renamed"); assert!(!Path::new(&day).exists()); + let moved = lib.join("Originals/Beach/a.jpg"); + assert_eq!(paths(&s), [moved.to_string_lossy().to_string()], "the catalog follows the photo"); + assert!(moved.is_file()); s.execute("edit.undo", &json!({})).unwrap(); assert!(Path::new(&day).is_dir(), "undo names it back"); + assert_eq!(paths(&s), [photo.to_string_lossy().to_string()], "and points the photo back, in one step"); + assert!(photo.is_file()); for own in ["Originals", "thumbs"] { std::fs::create_dir_all(lib.join(own)).unwrap(); let path = lib.join(own).to_string_lossy().to_string();