mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 09:26:43 +00:00
Cancel pending link scans when closing a document
Discard background scan results when a document closes so they cannot change the missing-link state after the same document reopens.
This commit is contained in:
2 files changed
+22
No files matched your search
@@ -371,6 +371,27 @@ mod tests {
|
||||
assert_eq!(s.missing_links().len(), 1, "the earlier look found the file, but it is gone");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_scan_finished_after_close_cannot_change_a_reopened_document() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join("art.png");
|
||||
let saved = directory.path().join("doc.pcraft");
|
||||
std::fs::write(&path, png(10, 10, "#ff0000")).unwrap();
|
||||
let (mut s, layer) = placed(&path);
|
||||
s.execute("file.saveACopy", json!({"path": saved.to_string_lossy()})).unwrap();
|
||||
let id = s.active().unwrap().doc.id;
|
||||
let stored = super::linked_files(&s.active().unwrap().doc)[0].0.clone();
|
||||
let scan = std::sync::Arc::new(std::sync::Mutex::new(None));
|
||||
s.link_scan = Some(scan.clone());
|
||||
s.close(0);
|
||||
let bytes = std::fs::read(&saved).unwrap();
|
||||
crate::file_cmds::open_bytes_as(&mut s, "doc.pcraft", &bytes, None, Some(saved.to_string_lossy().into_owned())).unwrap();
|
||||
assert_eq!(s.active().unwrap().doc.id, id);
|
||||
*scan.lock().unwrap() = Some((id.0, vec![(stored, vec![layer], None)]));
|
||||
assert!(s.poll_link_scan().is_none());
|
||||
assert!(s.missing_links().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_background_look_updates_changed_files() {
|
||||
let d = dir("scan");
|
||||
|
||||
@@ -141,6 +141,7 @@ impl Session {
|
||||
self.subject_cache.forget_doc(id);
|
||||
self.object_finder.forget_doc(id);
|
||||
self.link_missing.retain(|(d, _)| *d != id.0);
|
||||
self.link_scan = None;
|
||||
}
|
||||
let d = self.docs.remove(index);
|
||||
self.active = if self.docs.is_empty() {
|
||||
|
||||
Reference in new issue
Block a user