Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge PR #3141: Issue #2589: a reference app import never creates a photo already in Recently Deleted

aionggb3ddfefa5d29
diff --cc crates/engine/src/import/job.rs
index ac94f4030,baf4e2e70..3269edb02
--- a/crates/engine/src/import/job.rs
+++ b/crates/engine/src/import/job.rs
@@@ -1,6 -1,6 +1,6 @@@
use super::commit::{How, Plan, Slot, Transfer, commit_prepared, name_family, run_transfers, system_clock};
-use super::files::{expand, probe_all};
+use super::files::{Seen, expand, probe_all, reusable_probes, sidecars_of};
- use super::types::{ImportCandidate, ImportMode, ImportOptions, ImportReport, Kept, OnDeleted};
+ use super::types::{FileFacts, ImportCandidate, ImportMode, ImportOptions, ImportReport, Kept, OnDeleted};
use super::{HashMap, MediaKind, Path, PathBuf, Photo, PhotoId, ProbeInfo, Session, Source};
/// Import files/folders. See the module docs.
@@@ -333,18 -324,19 +336,17 @@@ impl ImportJob
break;
}
}
- if let Some(h) = &info.content_hash
- && !opts.local
- && let Some(existing) = self.by_hash.get(h)
- {
- self.done.fetch_add(1, Relaxed);
- plan.slots.push(Slot::Item(PreparedItem::Duplicate { path, existing: *existing, reason: "content", hash: Some(h.clone()) }));
- continue;
- }
+ // same bytes as a library photo: skipped below, once its capture time is known
+ let duplicate_of =
+ info.content_hash.as_ref().filter(|_| !opts.local).and_then(|h| self.by_hash.get(h).map(|existing| (h.clone(), *existing)));
// the XMP sidecar (or a raw's embedded XMP), read before copying: its capture time files
- // and names the copy when the file itself has none
+ // and names the copy when the file itself has none (a duplicate needs only that time)
let raw = info.kind == MediaKind::Raw;
- let packet = found_sidecar.and_then(|f| std::fs::read_to_string(f).ok()).or_else(|| info.xmp.clone().filter(|_| raw));
+ let packet = if duplicate_of.is_some() && info.captured.is_some() {
+ None
+ } else {
- crate::sidecar::find_sidecar_for_import(&stems, self.naming, &path)
- .and_then(|f| std::fs::read_to_string(f).ok())
- .or_else(|| info.xmp.clone().filter(|_| raw))
++ found_sidecar.and_then(|f| std::fs::read_to_string(f).ok()).or_else(|| info.xmp.clone().filter(|_| raw))
+ };
let target = crate::crs::Target::for_file(info.kind, &info.format, info.preview_only.is_some(), &info.meta.camera);
let sidecar = packet.and_then(|x| match crate::sidecar::parse_sidecar(&x, target) {
Ok(sc) => Some(sc),