Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion crates/catalog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ pub enum Op {
/// when it is `None`.
#[serde(default, skip_serializing_if = "String::is_empty")]
preview_checked: String,
/// The file is a JPEG cut short (see [`Photo::truncated`]). Absent in records written before
/// the field existed, which read as `false`; builds that don't know it ignore it.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
truncated: bool,
},
/// The lens data a photo's file carries (what Reload finds when it was read after import).
SetEmbeddedLens {
Expand Down Expand Up @@ -914,7 +918,7 @@ impl Catalog {
let old_format = format.map(|f| std::mem::replace(&mut p.format, f));
Op::Relink { id, file_name: old_name, source: std::mem::replace(&mut p.source, source), format: old_format }
}
Op::SetContent { id, width, height, file_size, content_hash, preview_only, preview_checked } => {
Op::SetContent { id, width, height, file_size, content_hash, preview_only, preview_checked, truncated } => {
let p = self.photo_mut(id)?;
Op::SetContent {
id,
Expand All @@ -924,6 +928,7 @@ impl Catalog {
content_hash: std::mem::replace(&mut p.content_hash, content_hash),
preview_only: std::mem::replace(&mut p.preview_only, preview_only),
preview_checked: std::mem::replace(&mut p.preview_checked, preview_checked),
truncated: std::mem::replace(&mut p.truncated, truncated),
}
}
Op::SetEmbeddedLens { id, lens } => {
Expand Down
7 changes: 7 additions & 0 deletions crates/catalog/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ pub struct Photo {
/// builds may decode the file, older ones may decode less.
#[serde(default, skip_serializing_if = "String::is_empty")]
pub preview_checked: String,
/// A JPEG that was cut short (an interrupted download or copy: no end-of-image marker) and is
/// shown from the data present. Set when the file is probed (import, Reload, Relink); never written
/// for a whole file, so a catalog without such photos is unchanged, and builds that don't
/// know the field read the photo without it.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub truncated: bool,
/// A Local record: the fingerprint of its state when the browse catalogued it, to tell
/// whether the user changed anything since (see [`crate::local`]).
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -393,6 +399,7 @@ impl Photo {
analysis: None,
preview_only: None,
preview_checked: String::new(),
truncated: false,
local_baseline: None,
}
}
Expand Down
13 changes: 11 additions & 2 deletions crates/catalog/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,22 @@ fn preview_only_survives_serde_and_set_content_undo() {
content_hash: None,
preview_only: Some("Nikon Huffman-compressed NEF".into()),
preview_checked: "0.6.0".into(),
truncated: false,
};
c.apply(op).unwrap();
assert_eq!(c.photo(a).unwrap().preview_checked, "0.6.0");
// Reload: the file decodes now → cleared, with its stamp; undo (through the journal's JSON)
// restores both
let op =
Op::SetContent { id: a, width: 6016, height: 4000, file_size: 1, content_hash: None, preview_only: None, preview_checked: String::new() };
let op = Op::SetContent {
id: a,
width: 6016,
height: 4000,
file_size: 1,
content_hash: None,
preview_only: None,
preview_checked: String::new(),
truncated: false,
};
let inv = c.apply(op).unwrap();
assert!(c.photo(a).unwrap().develops_raw());
assert_eq!(c.photo(a).unwrap().preview_checked, "");
Expand Down
39 changes: 39 additions & 0 deletions crates/catalog/src/tests_format_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,45 @@ fn v6_preview_only_photo_loads_unstamped_and_is_upgraded() {
assert_eq!(snapshot_version(&m), u64::from(VERSION));
}

/// `Photo.truncated` and `Op::SetContent.truncated` are optional and written only when set, so
/// the format version stays (a library without such photos is byte-for-byte what it was; one with
/// them still opens in builds that don't know the field, which read the photo without it).
#[test]
fn truncated_mark_is_optional_and_needs_no_new_version() {
let mut c = Catalog::new();
let (a, b) = (c.alloc_photo_id(), c.alloc_photo_id());
for id in [a, b] {
let p = Photo::new(id, Source::File { path: format!("/p/{}.jpg", id.0) }, "a.jpg", "JPEG", 160, 120, "2026-01-01");
c.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap();
}
let plain = c.to_snapshot();
assert!(!plain.contains("truncated"), "a whole file leaves no trace");
let set = |truncated| Op::SetContent {
id: a,
width: 160,
height: 120,
file_size: 9,
content_hash: None,
preview_only: None,
preview_checked: String::new(),
truncated,
};
let inv = c.apply(set(true)).unwrap();
assert!(c.photo(a).unwrap().truncated && !c.photo(b).unwrap().truncated);
// through the snapshot, and through a journal record (the undo of Reload)
let m = MemStore::new();
m.set(SNAPSHOT, format!("{{\"format\":\"lightcraft-catalog\",\"version\":{VERSION},\"seq\":1,\"catalog\":{}}}\n", c.to_snapshot()).into_bytes());
let (_, loaded, r) = Journal::open(Box::new(m.clone())).unwrap();
assert!(loaded.photo(a).unwrap().truncated && !loaded.photo(b).unwrap().truncated);
assert_eq!(r.upgraded_from, None, "no upgrade: the version is the same");
// records written before the field existed read as `false`
let old: Op = serde_json::from_str(&serde_json::to_string(&set(false)).unwrap()).unwrap();
assert!(!serde_json::to_string(&old).unwrap().contains("truncated"));
c.apply(inv).unwrap();
assert!(!c.photo(a).unwrap().truncated);
assert_eq!(c.to_snapshot(), plain);
}

#[test]
fn versionless_log_only_library_is_upgraded() {
let mut c = Catalog::new();
Expand Down
Loading
Loading