diff --git a/crates/engine/src/cmd/links.rs b/crates/engine/src/cmd/links.rs index 2ceb25b5fa..509a3959cb 100644 --- a/crates/engine/src/cmd/links.rs +++ b/crates/engine/src/cmd/links.rs @@ -487,6 +487,24 @@ fn probe(g: &Group, base: LinkBase) -> (Status, Option) { (if same { Status::Ok } else { Status::Modified }, Some(f)) } +/// Whether [`probe`] would find group `g`'s file missing, without reading or hashing its content. +/// A changed file is opened to check it can be read, and nothing more: the canvas markers ask only +/// this, and with Update Links set to Manually a changed file keeps differing from its stored link, +/// so a full probe would read the whole file again on every look while the markers are on. +fn missing(g: &Group, base: LinkBase) -> bool { + #[cfg(test)] + probe_gate::hold(&g.link.path); + let Some(f) = locate(&g.link, base) else { return true }; + let l = &g.link; + if !g.plate_files.is_empty() && super::place::dcs::plate_files_changed(&g.plate_files, &f.path) { + return false; + } + if l.size == Some(f.size) && l.modified.is_some() && l.modified == f.modified { + return false; + } + fileio::read_file_head(&f.path, 0).is_err() +} + /// Is image `key` of `d` showing its preview (its file not read)? fn previewing(d: &Document, key: &str) -> bool { d.images.get(key).is_none_or(ImageBlob::is_proxy) @@ -2554,7 +2572,7 @@ pub(crate) fn statuses(st: &crate::DocState) -> BTreeMap Vec { groups(doc, None) .iter() - .filter(|g| !g.ids.is_empty() && probe(g, base).0 == Status::Missing) + .filter(|g| !g.ids.is_empty() && missing(g, base)) .flat_map(|g| g.ids.iter().copied()) .filter(|id| doc.is_visible(*id)) .collect() diff --git a/crates/engine/src/tests/missing_links.rs b/crates/engine/src/tests/missing_links.rs index f093a36ec2..277d92b648 100644 --- a/crates/engine/src/tests/missing_links.rs +++ b/crates/engine/src/tests/missing_links.rs @@ -131,6 +131,7 @@ fn turning_missing_links_on_returns_before_the_file_probe_and_scans_on_the_link_ // The toggle returns while the probe of the (slow) linked file is held closed. assert_eq!(s.execute("view.showMissingLinks", &json!({"on": true})).unwrap(), json!({"on": true})); assert!(!gate.finished(), "the toggle waited for the file probe"); + assert_eq!(gate.entered(Duration::ZERO), None, "the toggle probed the file on the calling thread"); assert!(s.doc().unwrap().missing_link_markers.is_none()); assert!(s.doc().unwrap().marked_missing_links().is_empty()); // The desktop app starts the watcher's look at once, and the probe runs there.