Skip to content

Commit 23c3af6

Browse files
THEtheChadclaude
andcommitted
refactor(lightroom): check the catalog's capture time in a helper (storytold#1588)
On main after storytold#3430, storytold#3141's content-duplicate branch and this PR's capture time check together put `apply_prepared` over the cognitive-complexity limit (31/30), so clippy failed. The capture-time check moves unchanged into `catalog_capture_time`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 873389f commit 23c3af6

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

‎crates/engine/src/lightroom_catalog.rs‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,20 +1556,7 @@ pub(crate) fn apply_prepared(s: &mut crate::Session, mut data: CatalogImport, co
15561556
_ => Flag::None,
15571557
};
15581558
p.label = s.catalog.label_from_name(text(&src.image, "colorLabels"));
1559-
// A capture time the catalog can't hold would fail the whole batch at `SetCaptured`, and an
1560-
// impossible date (2026-02-30) would roll over to another day in date grouping.
1561-
let captured = text(&src.image, "captureTime");
1562-
if lightcraft_catalog::dates::normalize_iso(captured).is_some() {
1563-
p.captured = Some(captured.into());
1564-
} else if !captured.is_empty() {
1565-
warnings.push(format!("image {}: capture time “{captured}” is not a date; imported without it", src.source_id));
1566-
}
1567-
// a new record (a virtual copy, a duplicate) doesn't inherit a time an earlier import stored unchecked
1568-
if s.catalog.photo(p.id).is_none()
1569-
&& let Some(inherited) = p.captured.take_if(|c| lightcraft_catalog::dates::normalize_iso(c).is_none())
1570-
{
1571-
warnings.push(format!("image {}: inherited capture time “{inherited}” is not a date; imported without it", src.source_id));
1572-
}
1559+
catalog_capture_time(s, &mut p, src, &mut warnings);
15731560
if !src.keywords.is_empty() {
15741561
p.meta.keywords = src.keywords.clone();
15751562
}
@@ -1652,6 +1639,24 @@ pub(crate) fn apply_prepared(s: &mut crate::Session, mut data: CatalogImport, co
16521639
})
16531640
}
16541641

1642+
/// Gives `p` the catalog's capture time when it is a date. A capture time the catalog can't hold
1643+
/// would fail the whole batch at `SetCaptured`, and an impossible date (2026-02-30) would roll over
1644+
/// to another day in date grouping.
1645+
fn catalog_capture_time(s: &crate::Session, p: &mut Photo, src: &CatalogPhoto, warnings: &mut Vec<String>) {
1646+
let captured = text(&src.image, "captureTime");
1647+
if lightcraft_catalog::dates::normalize_iso(captured).is_some() {
1648+
p.captured = Some(captured.into());
1649+
} else if !captured.is_empty() {
1650+
warnings.push(format!("image {}: capture time “{captured}” is not a date; imported without it", src.source_id));
1651+
}
1652+
// a new record (a virtual copy, a duplicate) doesn't inherit a time an earlier import stored unchecked
1653+
if s.catalog.photo(p.id).is_none()
1654+
&& let Some(inherited) = p.captured.take_if(|c| lightcraft_catalog::dates::normalize_iso(c).is_none())
1655+
{
1656+
warnings.push(format!("image {}: inherited capture time “{inherited}” is not a date; imported without it", src.source_id));
1657+
}
1658+
}
1659+
16551660
/// The collection set a Lightroom collection's album goes into (`None`: the top level), and whether that isn't its
16561661
/// Lightroom parent. A LightCraft album nests only in a folder, but Lightroom also keeps a print, book, slideshow or
16571662
/// web gallery (or, in an odd catalog, a collection) inside a plain or smart collection, and a parent can be

0 commit comments

Comments
 (0)