Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b6b4662
fix(lightroom): a content duplicate keeps what its XMP sidecar says (…
THEtheChad Oct 31, 2026
752065d
fix(lightroom): only the Lightroom import reads a content duplicate's…
THEtheChad Nov 2, 2026
f840d2d
test(lightroom): a content duplicate's sidecar regions turn by its fi…
THEtheChad Nov 5, 2026
b5127e5
test(lightroom): a file that turns out to be a content duplicate at c…
THEtheChad Nov 9, 2026
f41b451
Issue #2589: a Lightroom import says where each catalog photo went
THEtheChad Oct 27, 2026
603618a
fix(lightroom): refused-path warnings no longer say "listed as missin…
THEtheChad Oct 27, 2026
49966a1
fix(lightroom): a refused photo with id 0 refuses only itself (#2589)
THEtheChad Oct 30, 2026
236fb68
docs(lightroom): a catalog video is a record now, not "not supported"…
THEtheChad Nov 1, 2026
fa5c815
fix(lightroom): the result window names at most eight unsupported fil…
THEtheChad Nov 2, 2026
0c981d5
fix(lightroom): inspecting a catalog doesn't list refused paths as mi…
THEtheChad Nov 4, 2026
e75c59b
fix(lightroom): the toast says unreadable originals apart from where …
THEtheChad Nov 4, 2026
445b1cf
Issue #2589: the inspect report test builds a catalog with main's bac…
THEtheChad Nov 11, 2026
4a28737
fix(engine): #3707 a Lightroom import develops the records it adds fr…
THEtheChad Nov 3, 2026
87c8fca
refactor(engine): one origin per record for a Lightroom import job
THEtheChad Nov 3, 2026
eae4a13
test(engine): pin each record origin's report counts and the job's du…
THEtheChad Nov 4, 2026
5987ef0
fix(engine): #3434 a record a Lightroom import makes starts from the …
THEtheChad Nov 4, 2026
bce9ef7
fix(engine): #3434 a photo browsed in Local and untouched since is on…
THEtheChad Nov 4, 2026
e2cf557
fix(engine): unreadable catalog develop text leaves a made record as …
THEtheChad Nov 4, 2026
3848d84
fix(engine): a Lightroom import reports what a made record's XMP side…
THEtheChad Nov 4, 2026
d4b123c
fix(ui-egui): the refused-paths line says what the warnings name
THEtheChad Nov 4, 2026
9891997
fix(engine): catalog masters at one path go on from what the earlier …
THEtheChad Nov 4, 2026
aa3c77e
Issue #3736: unit tests for a record's origin and the first origin re…
THEtheChad Nov 6, 2026
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
2 changes: 2 additions & 0 deletions crates/engine/src/cmd/library/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ pub fn import_params(s: &Session, p: &Value) -> Result<ImportRequest> {
metadata_preset,
convert_dng: bool_or(p, "dng", false),
local: bool_or(p, "local", false),
// (only the Lightroom import makes records of duplicates)
same_content: crate::import::SameContent::Skip,
recipe: crate::cmd::recipe_param(p, "library.import")?,
};
let album_name = str_param(p, "albumName").map(str::trim).filter(|n| !n.is_empty()).map(str::to_string);
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/library/specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ pub fn specs() -> Vec<CommandSpec> {
let temp = crate::lightroom_catalog::backup_temp_root(s);
let data = crate::lightroom_catalog::read_source(std::path::Path::new(path), temp.as_deref(), &cancel, &total, &done)
.map_err(|e| bad("library.inspectLightroom",e))?;
Ok(json!({"photos":data.photos.len(),"collections":data.collections.iter().filter(|r|r.get("systemOnly").and_then(Value::as_f64).unwrap_or(0.0)==0.0).count(),"missing":data.photos.iter().filter(|p| !p.original_is_file()).map(|p|&p.path).collect::<Vec<_>>(),"warnings":data.warnings,"skipped":data.skipped}))
Ok(json!({"photos":data.photos.len(),"collections":data.collections.iter().filter(|r|r.get("systemOnly").and_then(Value::as_f64).unwrap_or(0.0)==0.0).count(),"missing":data.photos.iter().filter(|p| p.original_is_missing()).map(|p|&p.path).collect::<Vec<_>>(),"warnings":data.warnings,"skipped":data.skipped}))
}),
cmd!(
"library.importLightroom",
Expand Down
3 changes: 2 additions & 1 deletion crates/engine/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mod job;
mod scan;
mod types;

pub(crate) use commit::start_from_file;
#[cfg(not(target_arch = "wasm32"))]
pub(crate) use commit::workers;
pub use commit::{batch_size, civil, commit_prepared, system_clock};
Expand All @@ -63,7 +64,7 @@ pub use scan::{
use scan::{library_files, library_hashes};
pub use types::{
Duplicate, FileFacts, ImportCandidate, ImportMode, ImportOptions, ImportReport, ImportUprightMode, ImportWarning, ImportWarningCode, Kept, Moved,
OnDeleted, Organize,
OnDeleted, Organize, Origin, Origins, SameContent,
};

#[cfg(test)]
Expand Down
34 changes: 24 additions & 10 deletions crates/engine/src/import/commit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::defaults::apply_import_defaults;
use super::files::copy_into;
use super::job::{Prepared, PreparedItem, ReadyFile};
use super::types::{Duplicate, ImportOptions, ImportReport, Kept, Moved, OnDeleted};
use super::types::{Duplicate, FileFacts, ImportOptions, ImportReport, Kept, Moved, OnDeleted, Origin};
use super::{HashMap, Op, Path, PathBuf, Photo, PhotoId, ProbeInfo, Session, Source};

/// A batch's items in file order while its transfers are pending ([`ImportJob::run_plan`]).
Expand Down Expand Up @@ -181,6 +181,22 @@ fn trashed_file_is_gone(cat: &lightcraft_catalog::Catalog, id: PhotoId) -> bool
}
}

/// What a new record takes from its file, as a file import gives it: the file's metadata and
/// capture time, the import defaults, then its XMP sidecar. Returns the sidecar when it said
/// anything (labels read through the library's label names).
pub(crate) fn start_from_file(s: &Session, p: &mut Photo, file: FileFacts, now: &str) -> Option<crate::sidecar::SidecarData> {
let FileFacts { meta, captured, orientation, sidecar } = file;
p.meta = meta;
p.captured = captured;
apply_import_defaults(s, p);
let sc = sidecar.map(|sc| sc.resolve_label(&s.catalog)).filter(|sc| *sc != crate::sidecar::SidecarData::default())?;
// the photo is upright as the file's own orientation turns it, when the file states one
// (after the check above: an orientation alone isn't a sidecar that said something)
let sc = crate::sidecar::SidecarData { orientation: orientation.or(sc.orientation), ..sc };
crate::sidecar::merge_into(p, &sc, now);
Some(sc)
}

/// The catalog half of an import: add the photos [`ImportJob::prepare`] readied (one undoable op;
/// a Move's sources are removed once it is saved). On a failed commit a Move's placed files are
/// taken back.
Expand Down Expand Up @@ -213,6 +229,8 @@ pub fn commit_prepared(s: &mut Session, opts: &ImportOptions, now: &str, prepare
ops.push(Op::SetLocal { id, local: false });
}
report.imported.push(id.0);
// (read before the promotion is committed: a promoted record is no longer Local)
report.origins.record(id, s.catalog.photo(id).map_or(Origin::Promoted, |p| Origin::of(p)));
}
PreparedItem::Duplicate { path, existing, reason, hash, file } => {
let existing = existing.or_else(|| {
Expand Down Expand Up @@ -252,25 +270,20 @@ pub fn commit_prepared(s: &mut Session, opts: &ImportOptions, now: &str, prepare
purge.push(*old);
}
}
let sidecar = sidecar.map(|sc| sc.resolve_label(&s.catalog)).filter(|sc| *sc != crate::sidecar::SidecarData::default());
// the photo is upright as the file's own orientation turns it, when the file states one
let sidecar = sidecar.map(|sc| crate::sidecar::SidecarData { orientation: info.orientation.or(sc.orientation), ..sc });
// a copy is catalogued under its new name
let name = Path::new(&stored).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| path.clone());
let mut p = Photo::new(id, Source::File { path: stored }, &name, &info.format, info.width, info.height, &now);
p.kind = info.kind;
p.file_size = info.file_size;
p.captured = info.captured;
p.meta = info.meta;
p.as_shot_wb = info.as_shot_wb;
p.content_hash = info.content_hash;
p.embedded_lens = info.embedded_lens;
p.set_preview_only(info.preview_only.clone());
apply_import_defaults(s, &mut p);
if let Some(sc) = &sidecar {
crate::sidecar::merge_into(&mut p, sc, &now);
if let Some(sc) =
start_from_file(s, &mut p, FileFacts { meta: info.meta, captured: info.captured, orientation: info.orientation, sidecar }, &now)
{
report.sidecars += 1;
report.warnings.extend(sc.warnings.iter().cloned().map(|mut warning| {
report.warnings.extend(sc.warnings.into_iter().map(|mut warning| {
warning.path = path.clone();
warning
}));
Expand Down Expand Up @@ -305,6 +318,7 @@ pub fn commit_prepared(s: &mut Session, opts: &ImportOptions, now: &str, prepare
p.history.push(lightcraft_catalog::HistoryStep { label: "Import adjustments".into(), settings: d });
}
report.imported.push(id.0);
report.origins.record(id, Origin::Created);
p.local = opts.local;
if opts.local {
// the state as browsed: a later change keeps the record from being forgotten
Expand Down
21 changes: 13 additions & 8 deletions crates/engine/src/import/job.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::commit::{How, Plan, Slot, Transfer, commit_prepared, name_family, run_transfers, system_clock};
use super::files::{Seen, expand, probe_all, reusable_probes, sidecars_of};
use super::types::{FileFacts, ImportCandidate, ImportMode, ImportOptions, ImportReport, Kept, OnDeleted};
use super::types::{FileFacts, ImportCandidate, ImportMode, ImportOptions, ImportReport, Kept, OnDeleted, SameContent};
use super::{HashMap, MediaKind, Path, PathBuf, Photo, PhotoId, ProbeInfo, Session, Source};

/// Import files/folders. See the module docs.
Expand Down Expand Up @@ -144,7 +144,7 @@ impl Prepared {
existing: Some(existing),
reason: if existing_path.is_some() { "path" } else { "content" },
hash: info.content_hash,
file: Some(Box::new(FileFacts { meta: info.meta, captured: info.captured })),
file: Some(Box::new(FileFacts { meta: info.meta, captured: info.captured, orientation: info.orientation, sidecar })),
});
} else {
items.push(PreparedItem::Ready(Box::new(ReadyFile { path, stored, info, sidecar, placed })));
Expand Down Expand Up @@ -299,11 +299,15 @@ impl ImportJob {
// names asked of the disk, which on a network share made a folder of thousands of photos wait
// a round trip per name, one name after another.
let asked: Vec<&str> = todo.iter().zip(&probed).filter(|(_, p)| p.is_ok()).map(|(f, _)| f.as_str()).collect();
// (a file whose content the library has is skipped below as a duplicate: it asks the disk nothing)
// What the job makes of a file decides what is read of it: a file it makes a record of is
// read in full, its XMP sidecar included; a duplicate by content it skips (`SameContent`)
// asks the disk nothing here (#2954), and has its sidecar read below only for the capture
// time its file lacks.
let skips_duplicates = !opts.local && opts.same_content == SameContent::Skip;
let known: std::collections::HashSet<&str> = todo
.iter()
.zip(&probed)
.filter(|(_, p)| !opts.local && p.as_ref().is_ok_and(|i| i.content_hash.as_ref().is_some_and(|h| self.by_hash.contains_key(h))))
.filter(|(_, p)| skips_duplicates && p.as_ref().is_ok_and(|i| i.content_hash.as_ref().is_some_and(|h| self.by_hash.contains_key(h))))
.map(|(f, _)| f.as_str())
.collect();
let mut found =
Expand Down Expand Up @@ -338,13 +342,14 @@ impl ImportJob {
break;
}
}
// same bytes as a library photo: skipped below, once its capture time is known
// same bytes as a library photo: a duplicate below, once its capture time is known (and,
// when the job makes a record of it, once it is read as any such file is)
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 (a duplicate needs only that time)
// and names the copy when the file itself has none (a skipped duplicate needs only that time)
let raw = info.kind == MediaKind::Raw;
let packet = if duplicate_of.is_some() && info.captured.is_some() {
let packet = if duplicate_of.is_some() && skips_duplicates && info.captured.is_some() {
None
} else {
found_sidecar.and_then(|f| std::fs::read_to_string(f).ok()).or_else(|| info.xmp.clone().filter(|_| raw))
Expand All @@ -371,7 +376,7 @@ impl ImportJob {
existing,
reason: "content",
hash: Some(hash),
file: Some(Box::new(FileFacts { meta: info.meta, captured: info.captured })),
file: Some(Box::new(FileFacts { meta: info.meta, captured: info.captured, orientation: info.orientation, sidecar })),
}));
continue;
}
Expand Down
125 changes: 124 additions & 1 deletion crates/engine/src/import/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Deserialize, MediaKind, Photo, Serialize};
use super::{Deserialize, HashMap, MediaKind, Photo, PhotoId, Serialize};

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ImportMode {
Expand Down Expand Up @@ -67,6 +67,8 @@ pub struct ImportOptions {
pub metadata_preset: Option<String>,
/// Copy: raws are copied as DNG (Copy as DNG).
pub convert_dng: bool,
/// What the import makes of a file whose bytes a library photo already has.
pub same_content: SameContent,
/// A batch-edit recipe: develop control id / value pairs (e.g. `light.exposure` → 0.5),
/// applied to every imported photo *after* its XMP sidecar, camera default and import preset,
/// as one more History step (`Import adjustments`). Only the named controls change; the recipe
Expand All @@ -79,6 +81,77 @@ pub struct ImportOptions {
pub recipe: Vec<(String, f64)>,
}

/// What an import makes of a file whose bytes a library photo already has (a duplicate by
/// content). What is read of the file follows from it: a file the job makes a record of is read in
/// full, its XMP sidecar included; one it only matches to a library photo needs no more than its
/// capture time.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum SameContent {
/// No record: the report lists it in [`ImportReport::duplicates`]. Its sidecar is read only for
/// the capture time its file lacks, and not looked up otherwise (a round trip per name on a
/// network share, #2954).
#[default]
Skip,
/// A record of its own ([`Origin::Created`]), which the Lightroom catalog import makes from
/// [`Duplicate::file`] (catalogs hold distinct originals with identical bytes): read as any
/// file the job makes a record of, its XMP sidecar included (#2589).
Create,
}

/// Where a library record an import job made or landed on came from. The job keeps one origin per
/// record ([`Origins`]), set where the record is made or first matched, and what the import does
/// to a record follows from it: whether its develop settings are an edit to keep, and how the
/// report counts it.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Origin {
/// This job made it, from a file (its metadata, the import defaults, its XMP sidecar) or from a
/// Lightroom catalog, or it is a photo browsed in Local and not changed since, which holds only
/// what browsing read from its file, as a record made from that file would (#3434): nothing in
/// it is an edit made in the library.
Created,
/// A photo browsed in Local and changed since browsing that this job brought into the library:
/// there before the job, with the user's changes.
Promoted,
/// In the library before the job.
Existing,
}

impl Origin {
/// The origin of `p`, a record that was in the library or browsed in Local when the job found
/// it: [`Origin::Created`] if browsed and untouched since ([`Photo::untouched_local`]: any
/// change counts, a rating or keyword too), [`Origin::Promoted`] if browsed and changed,
/// [`Origin::Existing`] otherwise. Read before the job promotes it (a promoted record is no
/// longer Local).
pub fn of(p: &Photo) -> Origin {
if p.untouched_local() {
Origin::Created
} else if p.local {
Origin::Promoted
} else {
Origin::Existing
}
}

/// There before the job: what it has may be the user's own work.
pub fn was_there(self) -> bool {
self != Origin::Created
}
}

/// The origin of each record an import job made or landed on ([`Origin`]): the file import
/// records the ones it makes and promotes ([`ImportReport::origins`]), and a Lightroom catalog
/// import goes on with the same record for the ones it matches and makes.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Origins(HashMap<PhotoId, Origin>);

impl Origins {
/// `id`'s origin in this job: the one recorded first. A record the job made stays
/// [`Origin::Created`] when a later step of the job finds it in the library.
pub fn record(&mut self, id: PhotoId, origin: Origin) -> Origin {
*self.0.entry(id).or_insert(origin)
}
}

/// How copies are filed in the destination. The date is the capture time, else the time of the
/// import.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -171,11 +244,20 @@ pub struct FileFacts {
/// The capture time a file import gives it: the file's, else its XMP sidecar's, else the
/// file's modification time.
pub captured: Option<String>,
/// The file's own orientation, when it states one ([`crate::media::ProbeInfo::orientation`]): it turns what its
/// sidecar's regions were drawn on, the photo as stored, upright (#2674).
pub orientation: Option<lightcraft_geom::Orientation>,
/// Its XMP sidecar (or a raw's embedded XMP), which a file import merges into the record.
pub sidecar: Option<crate::sidecar::SidecarData>,
}

#[derive(Clone, Debug, Default, Serialize)]
pub struct ImportReport {
pub imported: Vec<u64>,
/// The origin of each record in `imported`: made from its file, or a photo browsed in Local
/// that joined the library. (Not in the report.)
#[serde(skip)]
pub origins: Origins,
pub duplicates: Vec<Duplicate>,
/// [`OnDeleted::Restore`]: photos brought back from Recently Deleted instead of imported.
#[serde(skip_serializing_if = "Vec::is_empty")]
Expand Down Expand Up @@ -253,3 +335,44 @@ pub struct Kept {
pub path: String,
pub reason: String,
}

#[cfg(test)]
mod tests {
use super::{Origin, Origins, Photo, PhotoId};

fn photo(local: bool) -> Photo {
let source = lightcraft_catalog::Source::File { path: "/photos/a.jpg".into() };
let mut p = Photo::new(PhotoId(1), source, "a.jpg", "JPEG", 20, 10, "before");
p.local = local;
p.set_local_baseline();
p
}

/// A photo browsed in Local and untouched since holds only what browsing read from its file,
/// so the job counts it as one it made (#3434); any change since browsing, a rating too, makes
/// it Promoted; a library record is Existing. Only a record the job made wasn't there before.
#[test]
fn a_record_s_origin_follows_from_what_it_was_when_the_job_found_it() {
let mut browsed = photo(true);
assert!(browsed.untouched_local());
assert_eq!(Origin::of(&browsed), Origin::Created);
browsed.rating = 3;
assert_eq!(Origin::of(&browsed), Origin::Promoted);
assert_eq!(Origin::of(&photo(false)), Origin::Existing);
let there: Vec<bool> = [Origin::Created, Origin::Promoted, Origin::Existing].map(Origin::was_there).into();
assert_eq!(there, [false, true, true]);
}

/// The first origin recorded for a record stands for the whole job: a record the job made stays
/// Created when a later step finds it in the library, and every later `record` returns it.
#[test]
fn the_first_origin_recorded_for_a_record_stands() {
let mut origins = Origins::default();
assert_eq!(origins.record(PhotoId(1), Origin::Created), Origin::Created);
assert_eq!(origins.record(PhotoId(1), Origin::Existing), Origin::Created);
assert_eq!(origins.record(PhotoId(1), Origin::Promoted), Origin::Created);
assert_eq!(origins.record(PhotoId(2), Origin::Promoted), Origin::Promoted);
assert_eq!(origins.record(PhotoId(2), Origin::Created), Origin::Promoted);
assert_eq!(origins.record(PhotoId(3), Origin::Existing), Origin::Existing);
}
}
4 changes: 4 additions & 0 deletions crates/engine/src/lightroom_archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ mod tests {
collection_content: Vec::new(),
warnings: Vec::new(),
skipped: Vec::new(),
images: 0,
not_supported: Default::default(),
}
}

Expand All @@ -553,6 +555,8 @@ mod tests {
collection_content: vec![BTreeMap::from([("rule".into(), serde_json::json!("rating > 3"))])],
warnings: vec!["one warning".into()],
skipped: Vec::new(),
images: 1,
not_supported: Default::default(),
}
}

Expand Down
Loading
Loading