Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,56 @@ mod tests {
assert_eq!(photos[0].relpath, "Rome/orphan.DNG");
assert!(photos[0].raw_relpath.is_none());
}

#[test]
fn edited_jpeg_dng_twins_index_as_one_photo() {
let (_tmp, root) = mini_library();
write_still(&root.join("Rome/DSC_0001-edited.jpg"));
std::fs::write(root.join("Rome/DSC_0001-edited.DNG"), b"dng").unwrap();
index_library(&root).unwrap();
let conn = catalog::open(&root, false).unwrap();
assert_eq!(catalog::count(&conn).unwrap(), 1);
let photos = catalog::photos_in_album(&conn, "Rome").unwrap();
assert_eq!(photos.len(), 1);
assert_eq!(photos[0].relpath, "Rome/DSC_0001-edited.jpg");
assert_eq!(
photos[0].raw_relpath.as_deref(),
Some("Rome/DSC_0001-edited.DNG")
);
}

#[test]
fn edited_jpeg_does_not_pair_with_original_dng() {
let (_tmp, root) = mini_library();
write_still(&root.join("Rome/DSC_0001-edited.jpg"));
std::fs::write(root.join("Rome/DSC_0001.DNG"), b"dng").unwrap();
index_library(&root).unwrap();
let conn = catalog::open(&root, false).unwrap();
assert_eq!(catalog::count(&conn).unwrap(), 2);
let photos = catalog::photos_in_album(&conn, "Rome").unwrap();
assert_eq!(photos.len(), 2);
let edited = photos
.iter()
.find(|p| p.relpath == "Rome/DSC_0001-edited.jpg")
.unwrap();
assert!(edited.raw_relpath.is_none());
let original_dng = photos
.iter()
.find(|p| p.relpath == "Rome/DSC_0001.DNG")
.unwrap();
assert!(original_dng.raw_relpath.is_none());
}

#[test]
fn lone_edited_dng_indexes_without_raw_twin() {
let (_tmp, root) = mini_library();
std::fs::write(root.join("Rome/DSC_0001-edited.DNG"), b"dng").unwrap();
index_library(&root).unwrap();
let conn = catalog::open(&root, false).unwrap();
assert_eq!(catalog::count(&conn).unwrap(), 1);
let photos = catalog::photos_in_album(&conn, "Rome").unwrap();
assert_eq!(photos.len(), 1);
assert_eq!(photos[0].relpath, "Rome/DSC_0001-edited.DNG");
assert!(photos[0].raw_relpath.is_none());
}
}
29 changes: 26 additions & 3 deletions src/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn is_jpeg_dng_still(path: &Path) -> bool {
let Some(stem) = path.file_stem().and_then(|s| s.to_str()) else {
return false;
};
if stem.is_empty() || is_edited_sidecar_stem(stem) {
if stem.is_empty() {
return false;
}
path.extension()
Expand All @@ -152,7 +152,7 @@ pub fn dng_twin_for_still(still: &Path) -> Option<PathBuf> {
pub fn jpeg_dng_still_for_raw(raw: &Path) -> Option<PathBuf> {
let parent = raw.parent()?;
let stem = raw.file_stem()?.to_str()?;
if stem.is_empty() || is_edited_sidecar_stem(stem) {
if stem.is_empty() {
return None;
}
jpeg_dng_still_at_stem(parent, stem)
Expand Down Expand Up @@ -295,13 +295,36 @@ mod tests {
}

#[test]
fn jpeg_dng_skips_edited_sidecar_stems() {
fn jpeg_dng_edited_sidecar_does_not_pair_with_original_dng() {
let dir = tempfile::tempdir().unwrap();
File::create(dir.path().join("DSC_0001-edited.jpg")).unwrap();
File::create(dir.path().join("DSC_0001.DNG")).unwrap();
let edited = dir.path().join("DSC_0001-edited.jpg");
assert!(!is_jpeg_dng_developed_still(&edited));
assert!(dng_twin_for_still(&edited).is_none());
assert!(!is_dng_raw_companion(&dir.path().join("DSC_0001.DNG")));
}

#[test]
fn jpeg_dng_edited_twins_pair_by_same_stem() {
let dir = tempfile::tempdir().unwrap();
File::create(dir.path().join("DSC_0001-edited.jpg")).unwrap();
File::create(dir.path().join("DSC_0001-edited.DNG")).unwrap();
let edited_jpg = dir.path().join("DSC_0001-edited.jpg");
let edited_dng = dir.path().join("DSC_0001-edited.DNG");
assert!(is_jpeg_dng_developed_still(&edited_jpg));
assert!(is_dng_raw_companion(&edited_dng));
assert_eq!(dng_twin_for_still(&edited_jpg).unwrap(), edited_dng);
assert_eq!(jpeg_dng_still_for_raw(&edited_dng).unwrap(), edited_jpg);
}

#[test]
fn lone_edited_dng_is_not_a_companion() {
let dir = tempfile::tempdir().unwrap();
File::create(dir.path().join("DSC_0001-edited.DNG")).unwrap();
let lone = dir.path().join("DSC_0001-edited.DNG");
assert!(!is_dng_raw_companion(&lone));
assert!(dng_twin_for_still(&lone).is_none());
}

#[test]
Expand Down
Loading