This commit is contained in:
Brandon Thomas
2026-10-23 17:21:16 -04:00
2 changed files with 22 additions and 5 deletions
+4 -5
View File
@@ -845,13 +845,12 @@ impl SyncCommit {
}
}
SyncStep::Remove(gone) => {
let ops: Vec<Op> = gone
.iter()
.filter(|id| s.catalog.photo(**id).is_some_and(|p| p.in_library()))
.map(|id| Op::SetDeleted { id: *id, deleted: true })
.collect();
let ids: Vec<PhotoId> = gone.into_iter().filter(|id| s.catalog.photo(*id).is_some_and(|p| p.in_library())).collect();
let mut ops: Vec<Op> = ids.iter().map(|id| Op::SetDeleted { id: *id, deleted: true }).collect();
let n = ops.len();
if n > 0 {
// Like `photo.delete`, take them out of their stacks.
ops.extend(s.catalog.remove_from_stacks_ops(&ids));
match s.commit("Remove Missing Photos", Op::Batch { ops }) {
Ok(()) => report.removed += n,
Err(e) => report.failed.push((String::new(), e.to_string())),
+18
View File
@@ -739,3 +739,21 @@ fn a_cancelled_scan_does_not_check_the_cached_probes_against_the_disk() {
let new = out.candidates.iter().find(|c| c.name == "new.png").expect("new.png is a candidate");
assert!(new.error.is_some(), "the cached probe was used after ✕: {new:?}");
}
#[test]
fn removing_missing_photos_takes_them_out_of_their_stacks() {
let dir = Scratch::new("remove-stacked");
let mut s = library(&dir);
let id = |s: &Session, name: &str| s.catalog.photos().find(|p| p.file_name == name).unwrap().id;
let (a, b) = (id(&s, "a.png"), id(&s, "b.png"));
let group = s.catalog.group_ops(a, &[b], true).unwrap();
s.catalog.apply(group).unwrap();
assert!(s.catalog.stack_of(b).is_some());
std::fs::remove_file(dir.path("trip/day1/b.png")).unwrap();
let r = s.execute("folder.synchronize", &json!({"path": dir.path("trip"), "removeMissing": true})).unwrap();
assert_eq!(r["removed"].as_u64(), Some(1), "{r}");
assert!(s.catalog.photo(b).unwrap().deleted);
assert!(s.catalog.stack_of(b).is_none(), "like photo.delete, a removed photo leaves its stack: {:?}", s.catalog.stack_of(b));
s.execute("edit.undo", &json!({})).unwrap();
assert!(s.catalog.stack_of(b).is_some(), "one undo step puts b back in its stack");
}