Skip to content

Commit aecf43b

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 62230ea commit aecf43b

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
@@ -1339,20 +1339,7 @@ pub(crate) fn apply_prepared(s: &mut crate::Session, mut data: CatalogImport, co
13391339
_ => Flag::None,
13401340
};
13411341
p.label = s.catalog.label_from_name(text(&src.image, "colorLabels"));
1342-
// A capture time the catalog can't hold would fail the whole batch at `SetCaptured`, and an
1343-
// impossible date (2026-02-30) would roll over to another day in date grouping.
1344-
let captured = text(&src.image, "captureTime");
1345-
if lightcraft_catalog::dates::normalize_iso(captured).is_some() {
1346-
p.captured = Some(captured.into());
1347-
} else if !captured.is_empty() {
1348-
warnings.push(format!("image {}: capture time “{captured}” is not a date; imported without it", src.source_id));
1349-
}
1350-
// a new record (a virtual copy, a duplicate) doesn't inherit a time an earlier import stored unchecked
1351-
if s.catalog.photo(p.id).is_none()
1352-
&& let Some(inherited) = p.captured.take_if(|c| lightcraft_catalog::dates::normalize_iso(c).is_none())
1353-
{
1354-
warnings.push(format!("image {}: inherited capture time “{inherited}” is not a date; imported without it", src.source_id));
1355-
}
1342+
catalog_capture_time(s, &mut p, src, &mut warnings);
13561343
if !src.keywords.is_empty() {
13571344
p.meta.keywords = src.keywords.clone();
13581345
}
@@ -1435,5 +1422,23 @@ pub(crate) fn apply_prepared(s: &mut crate::Session, mut data: CatalogImport, co
14351422
})
14361423
}
14371424

1425+
/// Gives `p` the catalog's capture time when it is a date. A capture time the catalog can't hold
1426+
/// would fail the whole batch at `SetCaptured`, and an impossible date (2026-02-30) would roll over
1427+
/// to another day in date grouping.
1428+
fn catalog_capture_time(s: &crate::Session, p: &mut Photo, src: &CatalogPhoto, warnings: &mut Vec<String>) {
1429+
let captured = text(&src.image, "captureTime");
1430+
if lightcraft_catalog::dates::normalize_iso(captured).is_some() {
1431+
p.captured = Some(captured.into());
1432+
} else if !captured.is_empty() {
1433+
warnings.push(format!("image {}: capture time “{captured}” is not a date; imported without it", src.source_id));
1434+
}
1435+
// a new record (a virtual copy, a duplicate) doesn't inherit a time an earlier import stored unchecked
1436+
if s.catalog.photo(p.id).is_none()
1437+
&& let Some(inherited) = p.captured.take_if(|c| lightcraft_catalog::dates::normalize_iso(c).is_none())
1438+
{
1439+
warnings.push(format!("image {}: inherited capture time “{inherited}” is not a date; imported without it", src.source_id));
1440+
}
1441+
}
1442+
14381443
#[cfg(test)]
14391444
mod tests;

0 commit comments

Comments
 (0)