From 5260206fd41b800ec6e51744ea152c017cfd2baa Mon Sep 17 00:00:00 2001 From: Antonio Sokic <5701985+finaler1x@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:46:15 +0100 Subject: [PATCH 1/3] Issue #3405: Auto Import waits for an import that starts during its listing An import, sync or Lightroom migration that started while the watched folder was listed made the scan mark the new files as tried without importing them, so they were skipped until restart. The listing's result is now dropped in that case and the next listing imports them. --- crates/ui-egui/src/app/frame.rs | 5 +++++ crates/ui-egui/src/tests/drop_import.rs | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index 6e92091c780..fed05d6b44e 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -97,6 +97,11 @@ impl LightcraftApp { Ok(l) => l, Err(e) => return log::debug!("auto import: {e}"), }; + // an import, sync or Lightroom migration that started while the folder was listed: scanning + // now would mark the new files as tried without importing them; the next listing picks them up + if app.import.is_some() || app.sync_run.is_some() || app.lightroom.is_some() { + return; + } let p = serde_json::json!({"listing": listing, "start": false}); let Ok(r) = app.session.execute("library.autoImportScan", &p) else { return }; let Some(mut params) = r.get("import").cloned().filter(|_| app.import.is_none()) else { return }; diff --git a/crates/ui-egui/src/tests/drop_import.rs b/crates/ui-egui/src/tests/drop_import.rs index 3d8031a69bd..af6556010cf 100644 --- a/crates/ui-egui/src/tests/drop_import.rs +++ b/crates/ui-egui/src/tests/drop_import.rs @@ -1107,3 +1107,22 @@ fn public_drop_take_preserves_reentered_barrier_order_and_clears_protection() { assert_eq!(photos(&h), 0, "neither taken handles nor refused arrivals replay"); } } + +/// An import that starts while Auto Import lists its watched folder: the new photo isn't marked as +/// tried and skipped, the next listing imports it once the other import is done. +#[test] +fn auto_import_waits_for_an_import_that_starts_during_its_listing() { + let dir = Scratch::new("auto-race"); + let mut h = app(&dir); + write_png(&dir.path("watch/w.png"), 3); + h.app.session.import_defaults.auto_folder = Some(dir.path("watch")); + // the first listing notes the file's size, the second (size unchanged) imports it + assert!(h.step_until(T, |h| h.app.tasks.is_running("Auto Import")), "the watched folder is listed"); + assert!(h.step_until(T, |h| !h.app.tasks.is_running("Auto Import"))); + assert_eq!(photos(&h), 0); + assert!(h.step_until(T, |h| h.app.tasks.is_running("Auto Import")), "and listed again"); + // the listing's result is applied on a later frame, after this import has started + h.app.import = Some(crate::import::ImportTask::new(vec![dir.path("trip")], json!({"mode": "add"}), 0, false)); + assert!(h.step_until(T, |h| photos(h) == 3), "the trip's two photos and the watched one arrive: {}", photos(&h)); + h.app.session.import_defaults.auto_folder = None; +} From 1c1bb4f6328341a44506f24ef301295771bfe35f Mon Sep 17 00:00:00 2001 From: Antonio Sokic <5701985+finaler1x@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:28:49 +0100 Subject: [PATCH 2/3] Issue #3405: Auto Import also waits for a scan, and its race tests apply the listing on cue A Local browse that finishes replaces app.import, so Auto Import now waits for import::running (an import, a scan or a pending review) both before listing and before applying a listing. The tests apply the listing with tasks::wait_for while the other import or browse runs instead of relying on frame order. --- crates/ui-egui/src/app/frame.rs | 9 +++--- crates/ui-egui/src/tests/drop_import.rs | 43 ++++++++++++++++++++----- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index fed05d6b44e..acf7753a0f7 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -85,7 +85,7 @@ impl LightcraftApp { if let Some(folder) = self.session.import_defaults.auto_folder.clone() { const LABEL: &str = "Auto Import"; if now - self.ui.auto_import_at >= 3.0 - && self.import.is_none() + && !import::running(self) && self.sync_run.is_none() && self.lightroom.is_none() && !self.tasks.is_running(LABEL) @@ -97,9 +97,10 @@ impl LightcraftApp { Ok(l) => l, Err(e) => return log::debug!("auto import: {e}"), }; - // an import, sync or Lightroom migration that started while the folder was listed: scanning - // now would mark the new files as tried without importing them; the next listing picks them up - if app.import.is_some() || app.sync_run.is_some() || app.lightroom.is_some() { + // an import, a scan (a finished Local browse replaces `app.import`), a sync or a Lightroom + // migration that started while the folder was listed: scanning now would mark the new files as + // tried without importing them; the next listing picks them up + if import::running(app) || app.sync_run.is_some() || app.lightroom.is_some() { return; } let p = serde_json::json!({"listing": listing, "start": false}); diff --git a/crates/ui-egui/src/tests/drop_import.rs b/crates/ui-egui/src/tests/drop_import.rs index af6556010cf..59492b62d5c 100644 --- a/crates/ui-egui/src/tests/drop_import.rs +++ b/crates/ui-egui/src/tests/drop_import.rs @@ -1108,21 +1108,48 @@ fn public_drop_take_preserves_reentered_barrier_order_and_clears_protection() { } } +/// Auto Import's second listing of `watch/w.png` on its worker thread (the first notes the file's size; the +/// second, size unchanged, imports it). +fn second_auto_import_listing(h: &mut Headless, dir: &Scratch) { + write_png(&dir.path("watch/w.png"), 3); + h.app.session.import_defaults.auto_folder = Some(dir.path("watch")); + assert!(h.step_until(T, |h| h.app.tasks.is_running("Auto Import")), "the watched folder is listed"); + assert!(h.step_until(T, |h| !h.app.tasks.is_running("Auto Import"))); + assert_eq!(photos(h), 0); + assert!(h.step_until(T, |h| h.app.tasks.is_running("Auto Import")), "and listed again"); +} + +/// Apply Auto Import's listing now, before another frame can change what runs. +fn apply_auto_import_listing(h: &mut Headless) { + let ctx = h.view.ctx.clone(); + assert!(crate::tasks::wait_for(&mut h.app, &ctx, "Auto Import", T), "the listing ends"); +} + /// An import that starts while Auto Import lists its watched folder: the new photo isn't marked as /// tried and skipped, the next listing imports it once the other import is done. #[test] fn auto_import_waits_for_an_import_that_starts_during_its_listing() { let dir = Scratch::new("auto-race"); let mut h = app(&dir); - write_png(&dir.path("watch/w.png"), 3); - h.app.session.import_defaults.auto_folder = Some(dir.path("watch")); - // the first listing notes the file's size, the second (size unchanged) imports it - assert!(h.step_until(T, |h| h.app.tasks.is_running("Auto Import")), "the watched folder is listed"); - assert!(h.step_until(T, |h| !h.app.tasks.is_running("Auto Import"))); - assert_eq!(photos(&h), 0); - assert!(h.step_until(T, |h| h.app.tasks.is_running("Auto Import")), "and listed again"); - // the listing's result is applied on a later frame, after this import has started + second_auto_import_listing(&mut h, &dir); h.app.import = Some(crate::import::ImportTask::new(vec![dir.path("trip")], json!({"mode": "add"}), 0, false)); + apply_auto_import_listing(&mut h); assert!(h.step_until(T, |h| photos(h) == 3), "the trip's two photos and the watched one arrive: {}", photos(&h)); h.app.session.import_defaults.auto_folder = None; } + +/// The same with a Local folder browse: a browse that finishes replaces `app.import`, so Auto Import +/// doesn't start one beside it. +#[test] +fn auto_import_waits_for_a_browse_that_starts_during_its_listing() { + let dir = Scratch::new("auto-browse"); + let mut h = app(&dir); + second_auto_import_listing(&mut h, &dir); + let scan = crate::import::stall_scan_of(&mut h.app, true); + apply_auto_import_listing(&mut h); + assert!(h.app.import.is_none(), "no Auto Import for the browse to replace"); + drop(scan); + assert!(h.step_until(T, |h| h.app.scan.is_none()), "the browse ends"); + assert!(h.step_until(T, |h| photos(h) == 1), "and the watched photo arrives: {}", photos(&h)); + h.app.session.import_defaults.auto_folder = None; +} From 2910705fa25236711046ca85aa3f6aa35efee840 Mon Sep 17 00:00:00 2001 From: Antonio Sokic <5701985+finaler1x@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:46:59 +0100 Subject: [PATCH 3/3] Issue #3405: Auto Import waits for Synchronize Folder's scan too The guards now also check app.sync (Synchronize Folder's first scan), not only sync_run. The browse test sends a real scan result, so the finished browse starts its own import as it would in use. --- crates/ui-egui/src/app/frame.rs | 9 +++++---- crates/ui-egui/src/tests/drop_import.rs | 16 +++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index acf7753a0f7..afde76e5579 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -86,6 +86,7 @@ impl LightcraftApp { const LABEL: &str = "Auto Import"; if now - self.ui.auto_import_at >= 3.0 && !import::running(self) + && self.sync.is_none() && self.sync_run.is_none() && self.lightroom.is_none() && !self.tasks.is_running(LABEL) @@ -97,10 +98,10 @@ impl LightcraftApp { Ok(l) => l, Err(e) => return log::debug!("auto import: {e}"), }; - // an import, a scan (a finished Local browse replaces `app.import`), a sync or a Lightroom - // migration that started while the folder was listed: scanning now would mark the new files as - // tried without importing them; the next listing picks them up - if import::running(app) || app.sync_run.is_some() || app.lightroom.is_some() { + // an import, a scan (a finished Local browse replaces `app.import`), a Synchronize Folder (its scan + // or its run) or a Lightroom migration that started while the folder was listed: scanning now would + // mark the new files as tried without importing them; the next listing picks them up + if import::running(app) || app.sync.is_some() || app.sync_run.is_some() || app.lightroom.is_some() { return; } let p = serde_json::json!({"listing": listing, "start": false}); diff --git a/crates/ui-egui/src/tests/drop_import.rs b/crates/ui-egui/src/tests/drop_import.rs index 59492b62d5c..88f4c9a5457 100644 --- a/crates/ui-egui/src/tests/drop_import.rs +++ b/crates/ui-egui/src/tests/drop_import.rs @@ -1138,18 +1138,24 @@ fn auto_import_waits_for_an_import_that_starts_during_its_listing() { h.app.session.import_defaults.auto_folder = None; } -/// The same with a Local folder browse: a browse that finishes replaces `app.import`, so Auto Import -/// doesn't start one beside it. +/// The same with a Local folder browse: a browse that finishes replaces `app.import` with its own, so +/// Auto Import doesn't start one beside it. #[test] fn auto_import_waits_for_a_browse_that_starts_during_its_listing() { + use lightcraft_engine::import::{ImportCandidate, ScanOutput}; let dir = Scratch::new("auto-browse"); let mut h = app(&dir); second_auto_import_listing(&mut h, &dir); let scan = crate::import::stall_scan_of(&mut h.app, true); apply_auto_import_listing(&mut h); assert!(h.app.import.is_none(), "no Auto Import for the browse to replace"); - drop(scan); - assert!(h.step_until(T, |h| h.app.scan.is_none()), "the browse ends"); - assert!(h.step_until(T, |h| photos(h) == 1), "and the watched photo arrives: {}", photos(&h)); + // the browse finds one photo of its own and imports it + let Ok(tx) = scan.downcast::>() else { panic!("the stalled scan's sender") }; + let found = ImportCandidate { path: dir.path("trip/a.png"), ..Default::default() }; + tx.send(ScanOutput { candidates: vec![found], probes: Default::default() }).unwrap(); + drop(tx); + assert!(h.step_until(T, |h| h.app.import.is_some()), "the browse starts its import"); + assert!(h.step_until(T, |h| h.app.import.is_none()), "and it ends"); + assert!(h.step_until(T, |h| photos(h) == 2), "the browsed photo and the watched one arrive: {}", photos(&h)); h.app.session.import_defaults.auto_folder = None; }