LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge branch 'fix/issue-103-settings-files' into integrate/safety
Brandon Thomasa6b402981b85
diff --cc crates/engine/src/library.rsindex a068eaeb3,94ed050a3..616cfb0f8--- a/crates/engine/src/library.rs+++ b/crates/engine/src/library.rs@@@ -64,9 -64,12 +64,15 @@@ pub struct Librarypub forgot_local: Option<lightcraft_catalog::ForgetPlan>,presets_written: String,view_written: Vec<u8>,+ /// Settings files that were unreadable or damaged when the library opened (`library.info` →+ /// `settingsWarnings`; shown by the UI once, see [`Session::take_library_warnings`]).+ pub settings_warnings: Vec<String>,+ warnings_reported: usize,+ /// Settings files that couldn't be read or set aside: never overwritten this session.+ blocked: Vec<&'static str>,+ /// Keeps other processes out of this library while it's open (last: released after the+ /// journal's background snapshot has landed).+ lock: Option<LibraryLock>,}/// Where a library's files live (see [`Session::open_library_in`]).@@@ -174,25 -177,49 +180,66 @@@ fn poll_compaction(lib: &mut Library)/// How long the frame loop waits before retrying a failed append (commands retry at once).const RETRY_BACKOFF: std::time::Duration = std::time::Duration::from_secs(2);+/// `a` and `b` name the same directory.+fn same_dir(a: &Path, b: &Path) -> bool {+ match (std::fs::canonicalize(a), std::fs::canonicalize(b)) {+ (Ok(a), Ok(b)) => a == b,+ _ => a == b,+ }+}++/// This program, for the lock owner note ("LightCraft", "lightcraft-cli").+fn program_name() -> String {+ let exe = std::env::current_exe().ok().and_then(|p| p.file_stem().map(|s| s.to_string_lossy().to_string()));+ match exe.as_deref() {+ Some("lightcraft") | None => "LightCraft".into(),+ Some(other) => other.to_string(),+ }+}+- fn read_json<T: serde::de::DeserializeOwned>(store: &mut dyn Store, name: &str) -> Option<T> {- store.read(name).ok().flatten().and_then(|b| serde_json::from_slice(&b).ok())+ /// Problems reading the settings files (`presets.json`, `prefs.json`, `view.json`) when the library+ /// opened (issue #103). A missing file is not a problem (defaults). A file that doesn't parse is+ /// kept as `<name>.corrupt-<unix time>` before the defaults are used (so the next save can't+ /// lose it); a file that can't be read at all (locked by another program, I/O error) is never+ /// written this session, so its content survives until the library is opened again.+ #[derive(Default)]+ struct SettingsLoad {+ warnings: Vec<String>,+ /// Files not to overwrite this session.+ blocked: Vec<&'static str>,+ }++ impl SettingsLoad {+ fn read<T: serde::de::DeserializeOwned>(&mut self, store: &mut dyn Store, name: &'static str) -> Option<T> {+ let bytes = match store.read(name) {+ Ok(b) => b?,+ Err(e) => {+ log::error!("library: {name}: {e}");+ self.blocked.push(name);+ self.warnings.push(format!(+ "{name} couldn't be read ({e}). LightCraft uses the defaults for now and won't overwrite the file; reopen the library to try again."+ ));+ return None;+ }+ };+ let err = match serde_json::from_slice(&bytes) {+ Ok(v) => return Some(v),+ Err(e) => e,+ };+ let secs = web_time::SystemTime::now().duration_since(web_time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0);+ let keep = format!("{name}.corrupt-{secs}");+ log::error!("library: {name} is damaged: {err}");+ match store.write_atomic(&keep, &bytes) {+ Ok(()) => self.warnings.push(format!("{name} is damaged ({err}). It was kept as {keep}, and the defaults are used.")),+ Err(w) => {+ self.blocked.push(name);+ self.warnings.push(format!(+ "{name} is damaged ({err}) and couldn't be set aside ({w}). LightCraft uses the defaults and won't overwrite the file."+ ));+ }+ }+ None+ }}impl Session {@@@ -328,7 -325,9 +376,10 @@@forgot_local: None,presets_written,view_written,+ settings_warnings: settings.warnings,+ warnings_reported: 0,+ blocked: settings.blocked,+ lock: lock.take(),});// forget untouched Local records of folders not browsed for a while (journaled at once)if self.forget_local_days > 0 {diff --cc crates/ui-egui/src/control.rsindex b130c436b,4a30ae545..feaa847c4--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@@ -82,8 -82,9 +82,10 @@@ pub fn inspect(app: &LightcraftApp, ctx"loupe": app.loupe_shown.map(|(p, src)| json!({"photo": p.0, "source": src, "pending": app.renderer.is_pending(crate::render::Slot::Main)})),"hoverPreview": app.hover_preview.as_ref().map(|h| h.label.clone()),"status": app.ui.status,+ "notices": app.notices,+ "quitPrompt": app.quit_prompt,"unsaved": app.session.unsaved().map(|(n, e)| json!({"ops": n, "error": e})),+ "libraryProblem": app.library_problem.as_ref().map(crate::panels::library_problem::LibraryProblem::to_json),"scan": app.scan.as_ref().map(crate::import::ScanTask::status),"export": {"running": app.export.as_ref().map(crate::export_task::ExportTask::status), "last": app.last_export_result},"memory": memory(app),diff --cc crates/ui-egui/src/lib.rsindex 6700fbde2,046a320c7..b6ea924c4--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@@ -608,8 -617,8 +624,9 @@@ impl LightcraftApp// full-screen preview: the photo alone on blackegui::CentralPanel::default().frame(egui::Frame::NONE.fill(egui::Color32::BLACK)).show(ui, |ui| panels::detail::show(self, ui));panels::second::show(self, &ctx);+ panels::notices::show(self, &ctx);panels::dialogs::show(self, &ctx);+ panels::library_problem::show(self, &ctx);panels::toast(self, &ctx);self.widgets = widgets::take_registry(&ctx);self.end_frame(t0);@@@ -645,8 -653,8 +662,9 @@@state::ViewMode::Reference => panels::compare::show_reference(self, ui),});panels::second::show(self, &ctx);+ panels::notices::show(self, &ctx);panels::dialogs::show(self, &ctx);+ panels::library_problem::show(self, &ctx);import::progress(self, &ctx);import::scan_progress(self, &ctx);export_task::poll(self, &ctx);diff --cc crates/ui-egui/src/panels/mod.rsindex 8634ee341,3a0eb920b..4891ed8b7--- a/crates/ui-egui/src/panels/mod.rs+++ b/crates/ui-egui/src/panels/mod.rs@@@ -10,8 -10,8 +10,9 @@@ pub mod editpub mod filterbar;pub mod grid;pub mod left;+pub mod library_problem;pub mod masking;+ pub mod notices;pub mod presets;pub mod profiles;pub mod right;diff --cc docs/whats-new.mdindex d5e98932e,3eb8b36c0..2bb68baf8--- a/docs/whats-new.md+++ b/docs/whats-new.md@@@ -48,18 -19,13 +48,23 @@@in short pieces so slow integrated GPUs aren't reset by their watchdog. `ui.inspect` → `perf`(`gpuReason`, `gpuFallback`), Help ▸ System Info and Settings ▸ Performance say why the GPU isn'tused (e.g. a skipped software adapter such as llvmpipe) and why the last render fell back.+- The thumbnail cache only ever counts and deletes its own files (issue #98): a library opened on a folder that+ already has a `thumbs/` folder of other pictures no longer loses them when the cache is trimmed or cleared.+ - Settings files are never quietly reset (issue #103): a damaged `prefs.json`, `presets.json` or `view.json` is kept+ as `<name>.corrupt-<time>` and you're told; one that can't be read (e.g. locked by another program) is left alone+ for the session instead of being overwritten with defaults. The app settings (`ui.json`, which remembers your+ library) are written atomically and saved as soon as you open another library, not only at quit. Quitting while+ changes couldn't be saved tries once more, then asks: Try Saving Again, Quit Anyway or Cancel.### Library+- Rename Photos never overwrites another photo when only the letter case changes (issue #95): on case-sensitive+ volumes (Linux, case-sensitive APFS) `img_1.JPG` next to `IMG_1.JPG` is a different photo and the renamed one gets+ `img_1-1.JPG`; on case-insensitive volumes the case change still goes through.+- Rename Photos reports files it could not move back after a failure (issue #105), e.g. when a network share drops+ mid-batch: the error lists them (old → new) and the library points at their new names (an undoable partial rename),+ so none shows as missing. Renaming one of a raw + JPEG pair copies their shared `IMG_0001.xmp` instead of taking+ it away from the other (issue #92). Find Missing Photos also finds renamed files by their content, prefers a content match+ over a same-name same-size look-alike, and skips (and reports) photos it can't tell apart instead of guessing.- Smart albums with a rule editor: match all / any / none, nested groups, 26 fields.- Quick Collection and target album (B in the grid), keyword sets (⌥1–⌥9), colour-label sets.- Colour-label filter with several labels at once; expandable folder tree in Local.