Skip to content
Merged
25 changes: 18 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 61 additions & 4 deletions crates/engine/src/cmd/browse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ pub fn specs() -> Vec<CommandSpec> {
"{path, name}: rename a folder on disk (its files and sidecars go along) and relink the photos in it; one undo step (undo renames it back, refused if the old name is taken) → {path, relinked}",
always,
|s, p| {
let from = str_param(p, "path").ok_or_else(|| bad("folder.rename", "missing path"))?.trim_end_matches(['/', '\\']).to_string();
let from = str_param(p, "path").ok_or_else(|| bad("folder.rename", "missing path"))?.trim_end_matches(['/', '\\']);
let from = library_spelling(s, from);
let name = str_param(p, "name")
.map(str::trim)
.filter(|n| !n.is_empty() && !n.contains(['/', '\\']) && *n != "." && *n != "..")
Expand All @@ -302,10 +303,11 @@ pub fn specs() -> Vec<CommandSpec> {
"{path, into: destination folder}: move a folder on disk into another and relink the photos in it; one undo step (undo moves it back, refused if the old place is taken) → {path, relinked}",
always,
|s, p| {
let from = str_param(p, "path").ok_or_else(|| bad("folder.move", "missing path"))?.trim_end_matches(['/', '\\']).to_string();
let into = str_param(p, "into").ok_or_else(|| bad("folder.move", "missing into"))?;
let from = str_param(p, "path").ok_or_else(|| bad("folder.move", "missing path"))?.trim_end_matches(['/', '\\']);
let from = library_spelling(s, from);
let into = library_spelling(s, str_param(p, "into").ok_or_else(|| bad("folder.move", "missing into"))?);
let name = Path::new(&from).file_name().ok_or_else(|| bad("folder.move", "bad path"))?;
let to = Path::new(into).join(name).to_string_lossy().to_string();
let to = Path::new(&into).join(name).to_string_lossy().to_string();
let n = move_folder(s, &from, &to).map_err(|e| bad("folder.move", e))?;
Ok(json!({"path": to, "relinked": n}))
}
Expand Down Expand Up @@ -561,6 +563,43 @@ fn follow_library_folder(chosen: &mut Option<String>, from: &str, to: &str) {
}
}

/// `path` spelled the way the open library spells its own folder, when the two differ only in
/// letter case and name the same folder on disk (a volume that ignores letter case: Windows,
/// macOS); `path` as given otherwise. The library's photos are stored under its own spelling, so a
/// folder rename or move named through another spelling would match none of them and leave them
/// pointing at the old folder (upstream #4816; written for the fork, which compares the library's
/// protected folders on disk already).
fn library_spelling(s: &Session, path: &str) -> String {
let Some(lib) = s.library.as_ref().map(|l| l.dir.as_path()) else { return path.to_string() };
let given = Path::new(path);
let Some(rest) = case_only_rest(given, lib) else { return path.to_string() };
// the spelling given must be the library's own folder on disk: a volume that tells letter case
// apart can hold `LIB` next to `lib`, and then it is another folder
let prefix: std::path::PathBuf = given.components().take(lib.components().count()).collect();
let same = matches!((prefix.canonicalize(), lib.canonicalize()), (Ok(a), Ok(b)) if a == b);
if !same {
return path.to_string();
}
let spelled = if rest.as_os_str().is_empty() { lib.to_path_buf() } else { lib.join(rest) };
spelled.to_string_lossy().to_string()
}

/// What follows `lib` in `path` when `path` begins with `lib`'s names in other letter case;
/// `None` when it begins with `lib` exactly (nothing to respell) or with other names.
fn case_only_rest(path: &Path, lib: &Path) -> Option<std::path::PathBuf> {
if path.starts_with(lib) {
return None;
}
let mut names = path.components();
for l in lib.components() {
let p = names.next()?;
if p.as_os_str().to_string_lossy().to_lowercase() != l.as_os_str().to_string_lossy().to_lowercase() {
return None;
}
}
Some(names.as_path().to_path_buf())
}

/// Rename or move a folder on disk (everything in it goes along, sidecars included) and relink
/// the photos inside, as one undo step: undo renames the folder back and restores the photos'
/// paths, redo repeats the move — each refused (and reported) when the destination is taken.
Expand Down Expand Up @@ -618,3 +657,21 @@ pub(crate) fn move_folder(s: &mut Session, from: &str, to: &str) -> std::result:
follow_folder(s, from, to);
Ok(n)
}

#[cfg(test)]
mod tests {
use super::case_only_rest;
use std::path::{Path, PathBuf};

#[test]
fn a_path_that_differs_only_in_letter_case_is_respelled_under_the_library() {
let lib = Path::new("/photos/lib");
assert_eq!(case_only_rest(Path::new("/photos/LIB/Originals/day"), lib), Some(PathBuf::from("Originals/day")));
assert_eq!(case_only_rest(Path::new("/Photos/Lib"), lib), Some(PathBuf::new()), "the library itself");
assert_eq!(case_only_rest(Path::new("/photos/lib/Originals/day"), lib), None, "spelled exactly: nothing to respell");
assert_eq!(case_only_rest(Path::new("/photos/library/Originals"), lib), None, "another name is another folder");
assert_eq!(case_only_rest(Path::new("/photos"), lib), None, "a shorter path is not inside");
assert_eq!(case_only_rest(Path::new(""), lib), None);
assert_eq!(case_only_rest(Path::new("photos/LIB"), lib), None, "a relative path is not the library");
}
}
29 changes: 29 additions & 0 deletions crates/engine/src/tests_folders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,35 @@ fn a_date_folder_inside_the_library_can_be_renamed_but_the_librarys_own_folders_
assert!(lib.join("Originals").is_dir());
}

/// On a volume that ignores letter case (Windows, macOS), the library's folder named with other
/// letter case (`LIB/Originals/day` for `lib/Originals/day`) is the same folder: a rename through
/// that spelling relinks the photos stored under the library's own spelling, instead of moving the
/// folder on disk and leaving them pointing at the old one (upstream #4816).
#[test]
fn a_date_folder_named_with_other_letter_case_is_renamed_and_its_photos_follow() {
let dir = Scratch::new("in-library-case");
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 a = add_file(&mut s, &day.join("a.jpg").to_string_lossy(), "A");
let shouted = dir.0.join("LIB").join("Originals").join("2026-10-16");
if !shouted.is_dir() {
lcc_testkit::skip!(System, "this volume tells letter case apart");
return;
}
let r = s.execute("folder.rename", &json!({"path": shouted.to_string_lossy(), "name": "Beach"})).unwrap();
let moved = lib.join("Originals").join("Beach");
assert_eq!(r["relinked"], 1, "the photo inside is relinked: {r}");
assert_eq!(r["path"], moved.to_string_lossy().as_ref(), "the result names the library's own spelling");
assert!(moved.join("a.jpg").is_file());
assert_eq!(file_of(&s, a), moved.join("a.jpg").to_string_lossy(), "the catalog follows the photo");
s.execute("edit.undo", &json!({})).unwrap();
assert!(day.is_dir(), "undo names it back");
assert_eq!(file_of(&s, a), day.join("a.jpg").to_string_lossy());
}

#[cfg(unix)]
#[test]
fn the_library_folder_is_protected_however_its_path_is_spelled() {
Expand Down
18 changes: 17 additions & 1 deletion crates/ui-egui/src/panels/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,23 @@ pub fn show(app: &mut LccApp, ctx: &egui::Context) {
crate::widgets::named(ui.add(egui::TextEdit::multiline(&mut wm.text).desired_rows(2).hint_text(crate::i18n::tr("© Your Name")).desired_width(f32::INFINITY)), crate::i18n::tr("Text"))
});
}
choices(ui, "Position", "watermarkDialogAnchor", &WM_POSITIONS, &mut wm.anchor);
// a 3 × 3 grid laid out like the corners, edges and centre it picks (ids as before:
// `button:watermarkDialogAnchor-{0..8}`; adapted from upstream #4720)
field(ui, "Position", |ui| {
ui.vertical(|ui| {
ui.spacing_mut().item_spacing = egui::vec2(2.0, 2.0);
for (r, row) in WM_POSITIONS.chunks(3).enumerate() {
ui.horizontal(|ui| {
for (c, (v, l)) in row.iter().enumerate() {
let i = r * 3 + c;
if crate::widgets::text_button(ui, &format!("watermarkDialogAnchor-{i}"), l, wm.anchor == *v).clicked() {
wm.anchor = *v;
}
}
});
}
});
});
choices(ui, "Rotate", "watermarkDialogRotation", &[(0u16, "0°"), (90, "90°"), (180, "180°"), (270, "270°")], &mut wm.rotation);
let mut size = wm.size as f64 * 100.0;
if !graphic && num(ui, &WM_SIZE, &mut size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Aside } from '@astrojs/starlight/components';
- **Watermark** checkbox with a live preview on the photo.
- **Style**: **Text** or **Graphic** (an image file).
- **Text direction**: **Horizontal text** or **Vertical text** (columns run down, a newline starts the next column to the left; built for Japanese).
- **Position**: nine anchors; **Rotate** 0°, 90°, 180°, 270°.
- **Position**: nine anchors in a 3 × 3 grid laid out like the corners, edges and centre they pick; **Rotate** 0°, 90°, 180°, 270°.
- **Size** (% of short edge), **Opacity**, **Horizontal / Vertical inset**, **Shadow**.
- 🟡 Complex scripts: Thai mark positioning is incomplete and Arabic is not supported in the watermark. Japanese and Chinese need the bundled CJK fonts.
- Vertical text keeps Latin upright; no rotated runs, tate-chu-yoko or ruby.
Expand Down
Loading
Loading