Repository navigation
A failed Lightroom import takes back the photos it added - #4087
THEtheChad wants to merge 1 commit into
Conversation
…dded `lightroom_job::commit_prepared` commits the import's file step (records for the catalog's on-disk originals, and Local photos made the library's), then applies the catalog. When that failed (a capture time Lightroom keeps as a year or a month alone, collections it can't match safely, an album id it can't give), the error returned with the file step still committed: the originals stayed as records without the catalog's ratings, flags, edits or collections, and were saved to disk. The file step is now taken back when applying the catalog fails, as an undo would, without leaving a redo step. `Session::committed_step` records the one step committed since `Session::before_step`, and `Session::take_back` reverses only that step, refusing when anything was committed, undone or merged since. A step not yet written to the library's log leaves the queue, so neither it nor its reversal reaches the disk. When the take-back succeeds, the error is the one the import gave; when it fails, the error says so as well.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
… photos it added When the catalog step of a Lightroom import fails after the file step has added the catalog's originals, that step is taken back (Session::before_step / committed_step / take_back), and the original error is returned (combined if the take-back also fails). Ported by hand; the end-to-end failing-import tests are not ported (see PR notes). Adapted from upstream #4087 (head c728cd5580c7f4a1adfb51d25ee9f4aedbea75e2) Co-authored-by: THEtheChad <THEtheChad@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
vangel76
left a comment
There was a problem hiding this comment.
Reviewed c728cd55. I checked the failed-import rollback, including its effect on pre-existing undo and redo history. I found one history loss.
Source review only. I did not build the project, run tests, or check CI.
| 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()))?; |
There was a problem hiding this comment.
P2. Preserve the existing history when an import rolls back. The temporary file step commits first, which clears existing redo entries and can evict the oldest undo entry at the limit. Taking back the new catalog step does not restore them. Undo an edit and then attempt an import that fails during Lightroom metadata: the unrelated Redo is gone. Delay those history changes until success, or restore the pre-existing entries during rollback. Extend the failed-import fixture with an unrelated redo action.
wanikhawar
left a comment
There was a problem hiding this comment.
I checked the take-back against main. It is correct, and I'd take it for v0.22.1 (#4964):
import::commit_preparedcommits exactly one undo step, socommitted_stepfinds it. When the import adds nothing, it returnsNoneand nothing is taken back.- Every error in
apply_preparedcomes before its owns.commit, so the file step is still on top of the undo stack whentake_backruns. - Nothing is saved to disk mid-command, because
persistruns only at depth 0. So the queued op is normally still unwritten, and dropping it, rather than logging its reversal, is the right call.
Two notes, neither blocking:
- The redo history is still cleared by a failed import, as the earlier review found. The PR's Notes say so. Restoring it would mean holding back the file step's commit, so I'd leave that for a follow-up.
- When the reversal itself fails part way (
CatalogError::PartlyApplied),take_backpushes the whole entry back onto the undo stack.undo_stepinstead keeps only what is left (rest_of_partial_step). This is an edge case, but the two paths could share that handling.
Fixes #4086
Problem
A Lightroom catalog import can fail after its file step has already added the catalog's originals and promoted Local photos into the library. The person sees only the error. The records stay, saved to disk, without the catalog's ratings, edits, keywords or collections. A real catalog reaches this through a photo Lightroom dates by its year alone (#3501:
not a date: 2004).Change
crates/engine/src/lightroom_job.rs,commit_prepared: whenapply_preparedfails, take back the file step, then return the import's error. If the take-back also fails, the error says so, and its kind becomesOther.crates/engine/src/lib.rs:Session::before_step,committed_stepandtake_back.take_backundoes exactly the one step committed since the checkpoint. It refuses if anything was committed, undone, redone or merged since then. If the step hasn't reached the library's log yet, it is dropped from the queue. If it has, its reversal is logged like an undo.docs/lightroom-catalog-import.md: a failed import adds no photos.The step is taken back rather than checked in advance: the checks need the file step's result, and the catalog batch's commit can't be checked without applying it.
Tests
a_failed_import_takes_back_the_originals_it_addedanda_failed_import_leaves_the_photos_that_were_there_as_they_were(lightroom_catalog/tests.rs) run throughSession::executeon a library on disk and check it again after reopening.a_take_back_refuses_once_its_step_is_no_longer_the_last,a_take_back_drops_an_unwritten_step_and_logs_the_reversal_of_a_written_oneanda_step_that_cannot_be_taken_back_stays_on_the_undo_stack(lightroom_job.rs).Each fails with its part of the fix reverted: a plain
return Err(e)fails 2, the missing queue drop 3, logging the reversal after the step 2, and the guard removed 1.cargo xtask cipassed all 9 steps on this branch (onmainc2e9c45). Withlightcraft-clion a catalog with a year-only date,mainleaves 2 records and this branch 0. The desktop window was not run.Notes
commit_prepared. One bad Lightroom catalog record skips that record, not the import #3152 removes theerrorhelper this file still uses and turns a bad capture time into a warning, so the second test would need another trigger. There is also a semantic overlap with LR-BEHAV-AUTOSAVE: a change that could only be partly taken back is saved and can be undone #2797's undo failure arm.