Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

M-relink: file.import also drops the cached slate of media it brought back (#110)

Brandon Thomas4e4efcef125e
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index c342d7487..50ecc070d 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -889,9 +889,13 @@ fn build() -> Vec<CommandSpec> {
out["imageSequences"] = json!(image_sequences);
}
// Newly imported files may resolve paths the project already listed as offline
- // (issue #110): rebuild s.offline.missing so the slate / "Media missing" badge clear
- // without the user having to reopen the project or relink item-by-item.
+ // (issue #110): rebuild s.offline.missing so the "Media missing" badge clears, and drop
+ // the cached slate of every item that came back so the monitors show the file again.
+ let was_missing = s.offline.missing.clone();
crate::relink::refresh(s);
+ for item in was_missing.iter().filter(|i| !s.offline.missing.contains(i)) {
+ s.media.remove(*item);
+ }
Ok(out)
}),
cmd!(
diff --git a/crates/engine/src/relink_tests.rs b/crates/engine/src/relink_tests.rs
index 1d8c1dfc0..b3039d970 100644
--- a/crates/engine/src/relink_tests.rs
+++ b/crates/engine/src/relink_tests.rs
@@ -159,9 +159,11 @@ fn reimport_clears_offline_list_after_path_resolves() {
// Delete a.mov so the saved project now points at a missing file, then reopen:
// `on_open` → `refresh` → `scan` registers items[0] as missing.
+ let online = frame_rgba(&mut open(&path), 3, 1.0);
std::fs::remove_file(&a).unwrap();
let mut s = open(&path);
assert!(s.offline.missing.contains(&items[0]), "setup: a.mov missing on reopen");
+ assert_ne!(frame_rgba(&mut s, 3, 1.0), online, "setup: the slate shows while a.mov is missing");
// Recreate the file at the exact path the project stores, then import. `file.import`
// must drop items[0] from `s.offline.missing`. Without the fix, the entry stays stale
@@ -170,6 +172,8 @@ fn reimport_clears_offline_list_after_path_resolves() {
s.execute("file.import", json!({"paths": [a.to_string_lossy()]})).unwrap();
assert!(!s.offline.missing.contains(&items[0]), "issue #110 — file.import did not refresh s.offline.missing (still contains {:?})", s.offline.missing);
assert_eq!(s.execute("media.findMissing", json!({})).unwrap()["missing"].as_array().unwrap().len(), 0);
+ // and the monitors show the file again, not the cached slate
+ assert_eq!(frame_rgba(&mut s, 3, 1.0), online);
let _ = std::fs::remove_dir_all(&root);
}