Skip to content
Merged
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
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ never a panic. Never ship a panic path; fix crashes before building on them. Thi
"unsupported" error or disabled. Sole exception: provably infallible literal with
`#[allow(clippy::expect_used)]` + `.expect("why")`.
- `unsafe` lives only in: `crates/sysmem` (Win: `GetCurrentThread`+`SetThreadPriority` for render workers,
`GetDiskFreeSpaceExW` for cache sizing; macOS: `malloc_zone_pressure_relief` after raw decodes, `fsync` for SMB;
`GetDiskFreeSpaceExW` for cache sizing; macOS: `malloc_zone_pressure_relief` after raw decodes, `fsync` for SMB; glibc Linux: `malloc_trim` after raw
decodes and preview builds;
free space elsewhere = POSIX `df`), `crates/hdrmeta` (wgpu-hal: `VK_EXT_hdr_metadata` + `vkSetHdrMetadataEXT` on
Linux/BSD Wayland), `crates/gpumem` (wgpu-hal GPU memory budget for the HDR zoom cache), `crates/android-host`
(JNI VM/activity adoption), `crates/winspool` (Win32 print spooler), `crates/winmsi` (`MsiEnumClientsW` +
Expand Down
2 changes: 2 additions & 0 deletions crates/engine/src/cmd/previews.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ fn run_all(state: &PreviewBuild, task: &TaskGuard, lanes: usize, force: bool, ac
work(true);
}
state.finished.store(true, Ordering::Relaxed);
// the build's decode temporaries are gone: hand their pages back now, not at the next idle trim
crate::memory::release();
}

/// Wait while the user's own work runs ([`crate::activity::Activity::user_work`]), saying so in the
Expand Down
61 changes: 61 additions & 0 deletions crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@ use serde_json::Value;
pub use view::{Browse, FilterChip, LibrarySource, Selection, SelectionState, filter_chips};
pub use {lcc_catalog as catalog, lcc_develop as develop, lcc_gpu as gpu, lcc_pipeline as pipeline};

/// [`Session::before_step`]: the commit count and the length of the queue of ops not yet written to the library's log.
#[derive(Clone, Copy, Debug)]
pub(crate) struct BeforeStep {
commits: u64,
log: usize,
}

/// One step a command has just committed ([`Session::committed_step`]), to take back if the command then fails.
#[derive(Clone, Copy, Debug)]
pub(crate) struct CommittedStep {
/// [`Session::commits`] with the step committed.
commits: u64,
/// The undo stack's length with the step on top.
undo_len: usize,
/// Where the step's op waits in the queue for the library's log, while it hasn't been written.
pending: Option<usize>,
}

#[derive(Debug, thiserror::Error)]
pub enum EngineError {
#[error("unknown command `{0}`")]
Expand Down Expand Up @@ -1250,6 +1268,49 @@ impl Session {
rect
}

/// Where things stand before a command commits a step it may have to take back if it then fails
/// ([`Session::committed_step`]).
pub(crate) fn before_step(&self) -> BeforeStep {
BeforeStep { commits: self.commits, log: self.pending_log.len() }
}

/// The one step committed since `before`, for [`Session::take_back`]; `None` when no step, or more than one, was
/// committed since.
pub(crate) fn committed_step(&self, before: BeforeStep) -> Option<CommittedStep> {
(self.commits == before.commits.wrapping_add(1) && !self.undo.is_empty()).then(|| CommittedStep {
commits: self.commits,
undo_len: self.undo.len(),
pending: (self.pending_log.len() == before.log.saturating_add(1)).then_some(before.log),
})
}

/// Take back `step`, the step a command committed before it failed, as an undo would, with nothing left to redo.
/// Only that step: when anything was committed, undone or merged ([`Session::merge_undo`]) since it, the top of the
/// undo stack may be a step that isn't the command's, and this refuses instead. When the step isn't written to the
/// library's log yet, it leaves the queue, so neither it nor its reversal reaches the disk; otherwise the reversal
/// is logged like an undo. A step that can't be taken back stays on the undo stack, and the error says why.
pub(crate) fn take_back(&mut self, step: CommittedStep) -> Result<()> {
// A later commit changes the count; an undo, a redo or a merge changes the stack's length (at the cap a commit
// leaves the length as it was, but changes the count).
if self.commits != step.commits || self.undo.len() != step.undo_len {
return Err(EngineError::Other("the step to take back is no longer the last one".into()));
}
let mut e = self.undo.pop().ok_or_else(|| EngineError::Other("nothing to take back".into()))?;
if let Err(err) = self.apply_with_files(&mut e, &rename::RealFs) {
self.undo.push(e);
return Err(err);
}
self.drop_gone_from_selection();
self.reconcile_view();
// Dropping the queued step, rather than logging its reversal after it, keeps a write cut short (a crash, a full
// disk) from saving the step without its reversal: each op is its own record in the log.
match step.pending.filter(|at| at.saturating_add(1) == self.pending_log.len()) {
Some(at) => self.pending_log.truncate(at),
None => self.pending_log.push(e.op),
}
Ok(())
}

/// Apply an op that is the app's own bookkeeping rather than something the user did (faces found by the background
/// scan, a raw's as-shot white read by a decode, raws rechecked after an update): journaled like any op, but not
/// an undo step, and it leaves the redo stack alone.
Expand Down
8 changes: 8 additions & 0 deletions crates/engine/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ struct PrefsFile {
/// This library's own background preparation settings (`None`: the app-wide ones, [`crate::prep`]).
#[serde(skip_serializing_if = "Option::is_none")]
prep: Option<crate::prep::PrepSettings>,
/// A background build of this library's previews was started and has not run to its end: the
/// preparation takes it up again, also after a restart. Set and cleared by
/// [`Session::prep_tick`] only; the rules are at [`crate::prep::PrepState::unfinished`].
#[serde(skip_serializing_if = "std::ops::Not::not")]
prep_unfinished: bool,
/// Folder for smart previews (default: `Smart Previews` in the library).
smart_previews_dir: Option<String>,
/// Days after which untouched Local records of unbrowsed folders are forgotten (missing =
Expand Down Expand Up @@ -740,7 +745,9 @@ impl Session {
// photos with no camera-profile choice of their own start from these (issue #723)
lcc_raw::dcp::install_user_defaults(self.camera_profile_defaults.iter().map(|(k, v)| (k.clone(), v.clone())).collect());
self.cache_mb = prefs.cache_mb;
self.prep.opened_library();
self.prep.library = prefs.prep.map(crate::prep::PrepSettings::sanitized);
self.prep.unfinished = prefs.prep_unfinished;
self.preview_prefs = prefs.previews;
#[cfg(not(target_arch = "wasm32"))]
if on_disk {
Expand Down Expand Up @@ -1228,6 +1235,7 @@ impl Session {
camera_profile_defaults: self.camera_profile_defaults.clone(),
cache_mb: self.cache_mb,
prep: self.prep.library,
prep_unfinished: self.prep.unfinished,
smart_previews_dir: self.smart_previews_dir.as_ref().map(|d| d.to_string_lossy().to_string()),
forget_local_days: Some(self.forget_local_days),
// on disk they live in the catalog's settings (below)
Expand Down
Loading
Loading