mirror of
https://github.com/storytold/lightcraft.git
synced 2026-12-02 20:19:40 -05:00
LRC-LIB-LIBFOLDERS: refuse a path that reaches the library through a link below a case-distinct prefix
foreign_link_in_library_prefix now walks every component of the source, not only the library-length prefix, so a distinct LIB folder whose Originals is a link into the library is not rewritten and renamed as the library's own folder.
This commit is contained in:
1 parent
7911db589e
commit
078971ed08
2 files changed
+46
-4
No files matched your search
@@ -653,8 +653,10 @@ fn same_dir_entry(a: &Path, b: &Path) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the prefix of `src` that names the library walks through a link that is not the library's own path
|
||||
/// (a differently-cased spelling of the same folder is not a different path).
|
||||
/// Whether `src` walks through a link that is not the library's own path. The check covers every
|
||||
/// component, including those below the library root, so a distinct `LIB` folder whose `Originals`
|
||||
/// is a link into the library is refused. A differently-cased spelling of the same folder is not a
|
||||
/// different path.
|
||||
fn foreign_link_in_library_prefix(src: &Path, lib: &Path) -> bool {
|
||||
let lib_comps: Vec<_> = lib.components().collect();
|
||||
let src_comps: Vec<_> = src.components().collect();
|
||||
@@ -663,9 +665,13 @@ fn foreign_link_in_library_prefix(src: &Path, lib: &Path) -> bool {
|
||||
}
|
||||
let mut src_p = PathBuf::new();
|
||||
let mut lib_p = PathBuf::new();
|
||||
for (s, l) in src_comps.iter().zip(lib_comps.iter()) {
|
||||
for (i, s) in src_comps.iter().enumerate() {
|
||||
src_p.push(*s);
|
||||
lib_p.push(*l);
|
||||
if i < lib_comps.len() {
|
||||
lib_p.push(lib_comps[i]);
|
||||
} else {
|
||||
lib_p.push(*s);
|
||||
}
|
||||
if is_link(&src_p) && !same_dir_entry(&src_p, &lib_p) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -902,6 +902,42 @@ fn a_photo_stored_under_a_differently_cased_library_path_is_relinked() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A distinct folder whose name only differs in letter case, with a link below it into the library,
|
||||
/// must not be rewritten as the library's own path. Otherwise renaming it would move the real folder.
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn a_folder_reached_through_a_link_below_a_case_distinct_prefix_is_still_refused() {
|
||||
let dir = Scratch::new("link-below-case-prefix");
|
||||
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");
|
||||
std::fs::write(&photo, b"jpeg").unwrap();
|
||||
add(&mut s, &photo.to_string_lossy());
|
||||
let other = dir.0.join("LIB");
|
||||
if other.exists() {
|
||||
// the volume treats lib and LIB as one folder: the distinct-directory case does not arise
|
||||
return;
|
||||
}
|
||||
std::fs::create_dir_all(&other).unwrap();
|
||||
std::os::unix::fs::symlink(lib.join("Originals"), other.join("Originals")).unwrap();
|
||||
let linked = other.join("Originals").join("2026-10-16").to_string_lossy().to_string();
|
||||
let err = s.execute("folder.rename", &json!({"path": linked, "name": "Beach"})).unwrap_err().to_string();
|
||||
assert!(err.contains("give the folder's path inside the library"), "{err}");
|
||||
assert!(day.is_dir() && !lib.join("Originals").join("Beach").exists(), "the library folder was not renamed");
|
||||
let paths: Vec<_> = s
|
||||
.catalog
|
||||
.photos()
|
||||
.filter_map(|p| match &p.source {
|
||||
Source::File { path } => Some(path.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(paths, [photo.to_string_lossy().to_string()], "the catalog path is unchanged");
|
||||
}
|
||||
|
||||
/// On a case-sensitive volume, `trip` and `Trip` are different folders. Renaming one outside the
|
||||
/// library must not relink a photo in the other, or follow a browse of it.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user