Count duplicate originals once the sweep has dated them
A copy becomes a duplicate only once its capture time is read, and on a fresh library that is the sweep, not the scan: the sidebar row stayed hidden until the next launch. The count is refreshed when a sweep that dated anything finishes. Also says on a group left out of the plan that nothing will move, drops an unused method, and names the review's completion callback type for clippy.
This commit is contained in:
+43
-16
@@ -139,7 +139,10 @@ pub fn summarise(review: &[Reviewed]) -> Summary {
|
||||
#[derive(Debug)]
|
||||
pub enum DupMessage {
|
||||
/// One group checked, by its index in the review.
|
||||
Checked { index: usize, check: Check },
|
||||
Checked {
|
||||
index: usize,
|
||||
check: Check,
|
||||
},
|
||||
/// One group consolidated.
|
||||
Consolidated {
|
||||
index: usize,
|
||||
@@ -147,11 +150,19 @@ pub enum DupMessage {
|
||||
outcome: Outcome,
|
||||
},
|
||||
/// One group could not be consolidated and was left as it was.
|
||||
Failed { index: usize, reason: String },
|
||||
Progress { done: usize, total: usize },
|
||||
Failed {
|
||||
index: usize,
|
||||
reason: String,
|
||||
},
|
||||
Progress {
|
||||
done: usize,
|
||||
total: usize,
|
||||
},
|
||||
/// The job ended. `stopped` when the server went away or the review
|
||||
/// was closed.
|
||||
Finished { stopped: Option<String> },
|
||||
Finished {
|
||||
stopped: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
// ── the edit ─────────────────────────────────────────────────────────────
|
||||
@@ -748,8 +759,7 @@ pub fn spawn_consolidate(
|
||||
) -> Receiver<DupMessage> {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
std::thread::spawn(move || {
|
||||
let stopped =
|
||||
run_consolidate(&conn, &catalog_path, cache_dir, plans, &stop, &tx).err();
|
||||
let stopped = run_consolidate(&conn, &catalog_path, cache_dir, plans, &stop, &tx).err();
|
||||
let _ = tx.send(DupMessage::Finished { stopped });
|
||||
});
|
||||
rx
|
||||
@@ -922,7 +932,6 @@ mod tests {
|
||||
|
||||
// ── end to end, on a folder library ────────────────────────────────
|
||||
|
||||
|
||||
/// A folder library holding real files, and a catalog describing them.
|
||||
struct Library {
|
||||
dir: PathBuf,
|
||||
@@ -1092,7 +1101,11 @@ mod tests {
|
||||
assert_eq!(review.len(), 3);
|
||||
lib.check(&mut review);
|
||||
|
||||
assert!(matches!(review[0].check, Check::Same(_)), "{:?}", review[0].check);
|
||||
assert!(
|
||||
matches!(review[0].check, Check::Same(_)),
|
||||
"{:?}",
|
||||
review[0].check
|
||||
);
|
||||
assert_eq!(
|
||||
review[1].check,
|
||||
Check::Skip("The files differ in their first or last megabyte".into())
|
||||
@@ -1114,7 +1127,11 @@ mod tests {
|
||||
);
|
||||
|
||||
// What was read is kept: a second review needs no bytes.
|
||||
assert!(lib.review()[0].group.copies.iter().all(|c| c.probe.is_some()));
|
||||
assert!(lib.review()[0]
|
||||
.group
|
||||
.copies
|
||||
.iter()
|
||||
.all(|c| c.probe.is_some()));
|
||||
|
||||
let (done, failed) = lib.consolidate(&review);
|
||||
assert_eq!((done, failed), (1, Vec::<String>::new()));
|
||||
@@ -1137,10 +1154,9 @@ mod tests {
|
||||
assert_eq!(trashed(&cat), 2);
|
||||
|
||||
// The edit the backup copy carried now lives beside the survivor.
|
||||
let carried = std::fs::read_to_string(
|
||||
lib.lib.join(sidecar_path("2023/2023-06-24/_MG_4623.CR2")),
|
||||
)
|
||||
.unwrap();
|
||||
let carried =
|
||||
std::fs::read_to_string(lib.lib.join(sidecar_path("2023/2023-06-24/_MG_4623.CR2")))
|
||||
.unwrap();
|
||||
let carried = Sidecar::parse(&carried).unwrap();
|
||||
assert_eq!(
|
||||
edit_key(&carried),
|
||||
@@ -1165,7 +1181,10 @@ mod tests {
|
||||
assert_eq!(restored, 2);
|
||||
assert!(lib.exists("2023/bck/_MG_4623.CR2"));
|
||||
assert!(lib.exists("alps trip/Raw/20230628_0642.CR2"));
|
||||
assert_eq!(std::fs::read(lib.lib.join("2023/bck/_MG_4623.CR2")).unwrap(), frame);
|
||||
assert_eq!(
|
||||
std::fs::read(lib.lib.join("2023/bck/_MG_4623.CR2")).unwrap(),
|
||||
frame
|
||||
);
|
||||
assert_eq!(trashed(&lib.catalog()), 0);
|
||||
}
|
||||
|
||||
@@ -1193,7 +1212,11 @@ mod tests {
|
||||
assert_eq!(done, 0);
|
||||
assert_eq!(failed.len(), 1, "{failed:?}");
|
||||
|
||||
for path in ["2023/bck/IMG_0001.CR2", "2023/a/IMG_0001.CR2", "2023/b/IMG_0001-2.CR2"] {
|
||||
for path in [
|
||||
"2023/bck/IMG_0001.CR2",
|
||||
"2023/a/IMG_0001.CR2",
|
||||
"2023/b/IMG_0001-2.CR2",
|
||||
] {
|
||||
assert!(lib.exists(path), "{path} is back where it was");
|
||||
}
|
||||
assert!(!lib.exists(".darkroom-trash/1-IMG_0001.CR2"));
|
||||
@@ -1217,7 +1240,11 @@ mod tests {
|
||||
|
||||
let mut review = lib.review();
|
||||
lib.check(&mut review);
|
||||
assert!(matches!(review[0].check, Check::Same(_)), "{:?}", review[0].check);
|
||||
assert!(
|
||||
matches!(review[0].check, Check::Same(_)),
|
||||
"{:?}",
|
||||
review[0].check
|
||||
);
|
||||
let (done, failed) = lib.consolidate(&review);
|
||||
assert_eq!((done, failed), (1, Vec::<String>::new()));
|
||||
assert_eq!(trashed(&lib.catalog()), 1);
|
||||
|
||||
Reference in New Issue
Block a user