You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LR-LIB-DELETE: photo.trashFiles moves photos' files to the system Trash (stacked on #2927) - #2931
Stacked on #2927 (the plan and the work of Move Files to Trash), which is stacked on #1158 (the Trash back-end) and #2649 (the catalog's folder and name index); all three are off main, so until they land this diff also shows their commits, and this PR's own change is the last commit, 6f4a3feddc. Chain to main: #1158 and #2649, then #2927, then this PR (3b), then the background run (#2934), then the menu item and its questions.
Part of #565 (the "Delete from Disk" choice). This is the second half of the third of five pull requests that replace #1158 as it was first written.
Problem
After #1158 (the Trash) and #2927 (the plan that decides which files may go), nothing yet takes a photo out of the library and moves its file to the system Trash: there is no command for it, in the app or for an agent. Lightroom Classic's "Delete from Disk" has no counterpart here; Delete, Delete Permanently, Empty Recently Deleted and Remove Folder from Library all leave the file where it is.
Change
crates/engine/src/cmd/trash.rs (new), crates/engine/src/cmd/mod.rs, crates/engine/src/cmd/library.rs, crates/engine/src/trash_job.rs (drops the dead_code allowance #2927 added), crates/engine/src/tests_trash.rs, docs/whats-new.md, docs/parity-checklist.md, and one line in each of the 17 locale catalogs.
photo.trashFiles {ids?, noTrash?: keep|delete} takes the photos (ids, or the selection; in the library or in Recently Deleted) out of the library for good and moves their files, with their XMP sidecars, to the system Trash, as one undo step. Everything that can go goes; what cannot is named in the answer (noTrash, failed, shared, sidecarsLeft) and stays, photo and file. When nothing could go because a file failed, that is an error naming the reason. On a disk without a Trash the photos stay, named in noTrash, and their files are erased only when the call says noTrash: "delete"; a file the Trash refuses is never erased instead. A bad ids or noTrash is an error before anything moves. macOS, Linux and the other Unix systems; on Windows and in the browser the command says it is not available and changes nothing.
library.emptyRecentlyDeleted {files?: keep|trash, noTrash?}: with files omitted it does what it did, with the same answer. With files: "trash" it takes everything in Recently Deleted through the same command (deleted = removed). Both answers are checked before anything else, so a bad one is an error whatever Recently Deleted holds.
No menu item and no question. The command is for the control channel and MCP. Like every command it is listed in Help ▸ Keyboard Shortcuts, where a key can be bound to it; a bound key moves the selected photos' files to the Trash at once, without asking (a file moved to the Trash can be put back by Undo). The menu item with its questions comes in a later pull request.
The label "Move Files to Trash" (what Keyboard Shortcuts shows) is in all 17 catalogs.
Not in this PR: the background run with its activity row, cancellation and refusals (renames, moves, Convert to DNG, Undo and Redo while it works), and the menu item, the Delete question and the erase question.
cargo fmt --all --check and clippy with -D warnings on this branch; cargo test -p lightcraft-engine --lib (1,357 tests passed, at the previous head of this branch; the later changes were re-run with the 32 tests_trash tests, which pass), the i18n tests of lightcraft-ui-egui (37 passed), the parity tracker check, and the Markdown, spelling and link checks on the changed docs
6 tests in tests_trash.rs drive the two commands: the selection is what goes without ids, and ids win when given (undo brings the files back); everything in Recently Deleted goes at once and undo puts it back there, and a bad files moves nothing; Delete, Delete Permanently, Empty Recently Deleted and Remove Folder from Library still leave every file; noTrash default, "delete" and a bad value on both commands, and a file the Trash refuses is never erased instead; an empty list, an id that is not there, a browsed photo and a malformed list are refused.
Failing first, each run against a broken version in a throwaway worktree. files: "trash" treated as keep: everything_in_recently_deleted_goes_at_once_and_undo_brings_it_back_there fails (left: (Some(2), None) right: (Some(2), Some(2)): nothing was trashed). A bad noTrash accepted as keep: erasing_is_asked_for_by_name_and_only_for_disks_without_a_trash fails at the "shred" call. "delete" taken as keep, and ids ignored for the selection: erasing_is_asked_for_by_name…, empty_recently_deleted_takes_the_same_answer_about_disks_without_a_trash (left: (Some(0), Some(0)) right: (Some(1), Some(1))), the_selection_is_what_goes_without_ids_and_ids_win_when_given and the_photos_named_must_be_there_and_a_browsed_photo_is_refused fail. noTrash read only when files is "trash": empty_recently_deleted_takes_the_same_answer_about_disks_without_a_trash fails at its {"noTrash": "shred"} assertion.
A review of the first version found help text that described a background run that does not exist yet, a bad noTrash that was accepted when Recently Deleted was empty, the label missing from the catalogs, and tests that could not fail; all fixed. A second review asked that noTrash is read every time (done), and a third read the final version and found no defects.
Review: a fresh read-only reviewer at 6f4a3fe (29 Oct), reading LR-LIB-DELETE: the plan and the work of Move Files to Trash, run by tests only (stacked on #1158 and #2649) #2927's head 7491829ad5 to this head: no findings.
Existing edits and libraries: unchanged. No file format, setting or default changes; library.emptyRecentlyDeleted without the new parameters behaves as before.
Shared numbers taken: none.
Where it came from: own work.
New dependencies, unsafe, build scripts, network access, spawned processes, deleted files, CI or xtask gate changes: none in this PR. It is the first part where the command layer can move files to the Trash, or erase them on a disk without one when noTrash: "delete" is given.
Limits
Nothing records a run while it is under way: if the app is killed while files move, those already moved stay in the Trash (or are erased) and their photos show as missing.
The answer of library.emptyRecentlyDeleted {files: "trash"} is {deleted: 0} when Recently Deleted is empty, not the fuller answer of photo.trashFiles.
…folder / of this name" from an index
Two lookups the Trash work asks once per photo, so a big library answers from a map instead of
a pass over every photo: `photos_in_folder_any_case` and `photos_named_any_case`. Like the stack and
album lookups they are never saved, built on first use and kept up to date by `AddPhoto`,
`RemovePhoto`, `Relink` and `SetFile`. Nothing asks them yet, so nothing changes on screen.
Reviewing files that changed from the base of the PR and between 77c0a6a and 6f4a3fe.
Files ignored due to path filters: 1
Cargo.lock is excluded by !**/*.lock
Files selected for processing: 34
Cargo.toml
crates/catalog/src/index.rs
crates/catalog/src/lib.rs
crates/catalog/src/tests_folder_index.rs
crates/engine/Cargo.toml
crates/engine/src/cmd.rs
crates/engine/src/cmd/library.rs
crates/engine/src/cmd/library/selection.rs
crates/engine/src/cmd/library/specs.rs
crates/engine/src/cmd/trash.rs
crates/engine/src/lib.rs
crates/engine/src/tests.rs
crates/engine/src/tests/trash.rs
crates/engine/src/trash.rs
crates/engine/src/trash_job.rs
crates/ui-egui/locales/cs.json
crates/ui-egui/locales/de.json
crates/ui-egui/locales/es.json
crates/ui-egui/locales/fi.json
crates/ui-egui/locales/fr.json
crates/ui-egui/locales/id.json
crates/ui-egui/locales/it.json
crates/ui-egui/locales/ja.json
crates/ui-egui/locales/ka.json
crates/ui-egui/locales/pl.json
crates/ui-egui/locales/pt-br.json
crates/ui-egui/locales/ru.json
crates/ui-egui/locales/sv.json
crates/ui-egui/locales/uk.json
crates/ui-egui/locales/vi.json
crates/ui-egui/locales/zh-hans.json
crates/ui-egui/locales/zh-hant.json
docs/parity-checklist.md
docs/whats-new.md
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
Walkthrough
The change adds case-insensitive catalog indexes for file folders and names, system Trash operations with undo and redo, and commands to move eligible files to Trash. It also adds tests, documentation, and translations for the new behavior.
The catalog adds lazy folder and filename indexes, updates built indexes when photo file paths change, and tests lookup, update, and rollback behavior.
System Trash operations Cargo.toml, crates/engine/Cargo.toml, crates/engine/src/trash.rs, crates/engine/src/lib.rs
The engine adds a Trash interface and platform-specific implementations. The session now holds a Trash bin.
Trash planning, execution, and undo crates/engine/src/trash_job.rs, crates/engine/src/lib.rs, crates/engine/src/tests/trash.rs
The engine plans and processes file removals, handles shared files and sidecars, and records file operations for undo and redo. Tests cover command and filesystem outcomes.
Trash commands and supporting updates crates/engine/src/cmd/*, crates/engine/src/tests/trash.rs, crates/ui-egui/locales/*.json, docs/parity-checklist.md, docs/whats-new.md
The command registry adds photo.trashFiles, and library.emptyRecentlyDeleted accepts file-to-Trash options. Tests, documentation, and locale entries cover the additions.
sequenceDiagram
participant Command as photo.trashFiles
participant Plan as TrashPlan
participant Work as TrashWork
participant Bin as SystemBin
participant Session
Command->>Plan: create, survey, and resolve file plan
Command->>Work: run planned file operations
Work->>Bin: move eligible files to Trash
Work->>Session: commit removed photos with undo step
Session->>Bin: restore or retry files during undo or redo
Loading
Possibly related issues
Issue 2690: The change adds a Trash option for emptying Recently Deleted, but the issue’s deletion-date gap and bulk-exit concern are not addressed in the supplied change summary.
This adds commands that move photos and their files to the system Trash as a single undo step. Files are left in place on failure, on unsupported platforms, and on disks without a Trash unless the caller opts into erasure. No concrete merge-blocking issue was identified.
Security architecture risk: Moderate · up to 6f4a3
The workflow has useful safeguards: permanent deletion requires explicit permission, shared-file checks limit removal, and failed restores are reported. However, recovery relies on mutable filesystem paths, and an existing home Trash directory is not checked for privacy. Shared or concurrently modified storage can therefore redirect recovery, expose directory-protected photos, or undermine restore collision guarantees.
Retained concerns
Medium · security · inferred: Undo and redo retain pathnames rather than binding recovery to the original resolved parent and filesystem object. If another principal can replace a parent link in shared storage, undo can move a directory-protected photo into a different, potentially readable location. Redo can likewise trash a different same-named file after path replacement. This destructive lifecycle is new in the PR. Existing-destination checks and redo's refusal to erase do not establish parent or file identity.
Medium · security · inferred: The new freedesktop backend accepts an existing home Trash and its files/info directories without validating ownership, privacy, or symlink destinations. With effectively shared directories, moving a read-permissive photo out of a private source directory can expose its contents to other users. Newly created directories use mode 0700, and normally private desktop configurations mitigate this condition; those protections do not validate pre-existing or redirected home Trash locations.
Medium · reliability · inferred: The new put-back contract promises not to replace an occupied destination, but delegates to an existing helper that falls back from hard-link reservation to plain rename. Where hard links are unavailable, a destination created after the initial existence check can be overwritten during undo or commit-failure rollback. The helper predates this PR; its new use for Trash recovery introduces this exposure into the advertised restore guarantee. Existing tests cover an already occupied destination, not the fallback race.
Security review details
Security Blast Radius
inferred — Exposure is scoped to the application's filesystem authority, eligible catalog records, and associated sidecars—not a demonstrated cross-tenant service boundary. A call can name up to one million photos, and the bulk Recently Deleted option can apply the same destructive workflow to all deleted records. Filesystem path redirection can affect locations beyond the originally resolved photo folder.
Security Findings and Attack Paths
inferred — The identified attack paths require filesystem influence: control of a mutable path ancestor during recovery, or effective access to an existing non-private home Trash. They do not establish unauthenticated remote reachability. Under those conditions, the new workflow can redirect restored content or move private-directory content into a more accessible location.
Trust Boundaries and Controls
observed — Disk-local Trash validation rejects symlinks, foreign ownership, and non-private top-level Trash directories, using no-follow directory handles for checking. Replaceable disk roots are rejected or classified as lacking Trash according to whether a Trash entry exists. These checks do not run for the home-Trash branch.
Resilience and Maintainability Implications
observed — Tests cover occupied restore destinations, unavailable trashed files, retries, and erase-only redo leaving externally recreated files untouched. They demonstrate useful partial-failure containment, but do not establish identity preservation after a successful restore followed by replacement, or atomic collision safety on the rename fallback.
Hardening Proposals
proposed — Bind recovery to validated parent and file identities, reject changed provenance before redo, validate effective home-Trash privacy, and use atomic no-replace restoration or fail closed when the filesystem cannot provide it.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 64.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly identifies the primary change: adding photo.trashFiles to move photo files to the system Trash. The stacked PR reference is additional but does not obscure the purpose.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 64.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 74 functions across 13 files. (21 skipped: 21 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
Clippy (1.99.0)
Clippy execution timed out
Comment @coderabbitai help to get the list of available commands.
… it back
A new `trash` module: the `Bin` the engine moves files to, the real one behind it
(`SystemBin`: the Finder's Trash on macOS, the freedesktop.org Trash on the other Unixes, which
judges a disk's own Trash by the process's own user and never takes a link, a replaceable top or
a foreign folder for one), and `TrashStep`, the file work of an undo or redo step. No command
calls it yet: `photo.trashFiles` comes next.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2927 (the plan and the work of Move Files to Trash), which is stacked on #1158 (the Trash back-end) and #2649 (the catalog's folder and name index); all three are off
main, so until they land this diff also shows their commits, and this PR's own change is the last commit,6f4a3feddc. Chain tomain: #1158 and #2649, then #2927, then this PR (3b), then the background run (#2934), then the menu item and its questions.Part of #565 (the "Delete from Disk" choice). This is the second half of the third of five pull requests that replace #1158 as it was first written.
Problem
After #1158 (the Trash) and #2927 (the plan that decides which files may go), nothing yet takes a photo out of the library and moves its file to the system Trash: there is no command for it, in the app or for an agent. Lightroom Classic's "Delete from Disk" has no counterpart here; Delete, Delete Permanently, Empty Recently Deleted and Remove Folder from Library all leave the file where it is.
Change
crates/engine/src/cmd/trash.rs(new),crates/engine/src/cmd/mod.rs,crates/engine/src/cmd/library.rs,crates/engine/src/trash_job.rs(drops thedead_codeallowance #2927 added),crates/engine/src/tests_trash.rs,docs/whats-new.md,docs/parity-checklist.md, and one line in each of the 17 locale catalogs.photo.trashFiles {ids?, noTrash?: keep|delete}takes the photos (ids, or the selection; in the library or in Recently Deleted) out of the library for good and moves their files, with their XMP sidecars, to the system Trash, as one undo step. Everything that can go goes; what cannot is named in the answer (noTrash,failed,shared,sidecarsLeft) and stays, photo and file. When nothing could go because a file failed, that is an error naming the reason. On a disk without a Trash the photos stay, named innoTrash, and their files are erased only when the call saysnoTrash: "delete"; a file the Trash refuses is never erased instead. A badidsornoTrashis an error before anything moves. macOS, Linux and the other Unix systems; on Windows and in the browser the command says it is not available and changes nothing.library.emptyRecentlyDeleted {files?: keep|trash, noTrash?}: withfilesomitted it does what it did, with the same answer. Withfiles: "trash"it takes everything in Recently Deleted through the same command (deleted=removed). Both answers are checked before anything else, so a bad one is an error whatever Recently Deleted holds.Not in this PR: the background run with its activity row, cancellation and refusals (renames, moves, Convert to DNG, Undo and Redo while it works), and the menu item, the Delete question and the erase question.
How it was checked
7491829ad5) on 28 Oct: clippy on the whole workspace with-D warningsand Enforce Rust coding standards via Clippy #3111's lints andcargo fmt --all -- --checkpass at this head (with MENU-BAR: clippy passes on macOS again (Quit, About and Settings share one branch) #2973's one-file fix applied uncommitted for the run).cargo xtask ciat6f4a3feddc(run on this Mac with MENU-BAR: clippy passes on macOS again (Quit, About and Settings share one branch) #2973's one-file clippy fix applied uncommitted, then reverted): all 8 steps passed (fmt, clippy, heif, test, parity, layers, assets, wasm); the test step ran 5,303 tests, 0 failed, 44 ignored.cargo fmt --all --checkand clippy with-D warningson this branch;cargo test -p lightcraft-engine --lib(1,357 tests passed, at the previous head of this branch; the later changes were re-run with the 32tests_trashtests, which pass), the i18n tests oflightcraft-ui-egui(37 passed), the parity tracker check, and the Markdown, spelling and link checks on the changed docstests_trash.rsdrive the two commands: the selection is what goes withoutids, andidswin when given (undo brings the files back); everything in Recently Deleted goes at once and undo puts it back there, and a badfilesmoves nothing; Delete, Delete Permanently, Empty Recently Deleted and Remove Folder from Library still leave every file;noTrashdefault,"delete"and a bad value on both commands, and a file the Trash refuses is never erased instead; an empty list, an id that is not there, a browsed photo and a malformed list are refused.files: "trash"treated as keep:everything_in_recently_deleted_goes_at_once_and_undo_brings_it_back_therefails (left: (Some(2), None) right: (Some(2), Some(2)): nothing was trashed). A badnoTrashaccepted as keep:erasing_is_asked_for_by_name_and_only_for_disks_without_a_trashfails at the"shred"call."delete"taken as keep, andidsignored for the selection:erasing_is_asked_for_by_name…,empty_recently_deleted_takes_the_same_answer_about_disks_without_a_trash(left: (Some(0), Some(0)) right: (Some(1), Some(1))),the_selection_is_what_goes_without_ids_and_ids_win_when_givenandthe_photos_named_must_be_there_and_a_browsed_photo_is_refusedfail.noTrashread only whenfilesis"trash":empty_recently_deleted_takes_the_same_answer_about_disks_without_a_trashfails at its{"noTrash": "shred"}assertion.noTrashthat was accepted when Recently Deleted was empty, the label missing from the catalogs, and tests that could not fail; all fixed. A second review asked thatnoTrashis read every time (done), and a third read the final version and found no defects.Review: a fresh read-only reviewer at 6f4a3fe (29 Oct), reading LR-LIB-DELETE: the plan and the work of Move Files to Trash, run by tests only (stacked on #1158 and #2649) #2927's head
7491829ad5to this head: no findings.Screenshots
None: no visible change in this PR.
Merging
crates/engine/src/trash.rs,crates/engine/src/lib.rs,crates/engine/src/cmd/library.rsand the locale catalogs (see LR-LIB-DELETE: the engine can move a file to the system Trash and put it back #1158 and LR-LIB-DELETE: the plan and the work of Move Files to Trash, run by tests only (stacked on #1158 and #2649) #2927; I proposed on LR-LIB-DELETE-DISK: Delete asks Delete from Disk / Cancel / Remove, as in Lightroom (fixes #1706) #1851 that LR-LIB-DELETE: the engine can move a file to the system Trash and put it back #1158 lands as the back-end and LR-LIB-DELETE-DISK: Delete asks Delete from Disk / Cancel / Remove, as in Lightroom (fixes #1706) #1851 builds on it, and this command would then be reshaped to fit its dialog). A test merge with LRC-LIB-LIBFOLDERS: photos move to another folder in the background #1925, LRC-LIB-SMARTCOLL: a Same Content as Another Photo rule finds photos whose file is in the library twice #2043, LRC-LIB-MISSING: one rule for Missing Photos' files, and a folder listing that panics no longer stays running #2464 and LRC-LIB-LIBFOLDERS: a refused move to another folder says what is wrong in plain words; photo.checkMove and skip #2721 conflicts only indocs/parity-checklist.md(the Last updated line and the revision table's last row, which every PR touches) and, for LRC-LIB-SMARTCOLL: a Same Content as Another Photo rule finds photos whose file is in the library twice #2043, incrates/catalog/src/index.rs(LR-LIB-DELETE: the catalog answers "which photos have a file in this folder / of this name" from an index #2649's file); with LR-BEHAV-BG-TASKS: detached readers for an import or scan (stall, skip, cap), tested and not used yet #2378, PERF-SIDECARS: imports and moves answer sidecar lookups from the folder listing #2419 and LRC-LIB-LIBFOLDERS: the engine can locate a folder that is somewhere else now (engine only) #2860 it is clean.crates/engine/src/activity.rs,crates/engine/src/lib.rs,crates/engine/src/trash_job.rs,crates/engine/src/cmd/{browse,convert,edit,manage,missing,organize,trash}.rsandcrates/engine/src/tests_trash.rson top of this PR.library.emptyRecentlyDeletedwithout the new parameters behaves as before.unsafe, build scripts, network access, spawned processes, deleted files, CI orxtaskgate changes: none in this PR. It is the first part where the command layer can move files to the Trash, or erase them on a disk without one whennoTrash: "delete"is given.Limits
library.emptyRecentlyDeleted {files: "trash"}is{deleted: 0}when Recently Deleted is empty, not the fuller answer ofphoto.trashFiles.Checklist
docs/: What's New and the parity row and revisionSummary by CodeRabbit