FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Forced relink and Replace Footage keep the new file's properties (#534)
MarekSpodBiedry09d5473645c4
diff --git a/crates/engine/src/relink.rs b/crates/engine/src/relink.rsindex d8f0a9aa3..7037404ab 100644--- a/crates/engine/src/relink.rs+++ b/crates/engine/src/relink.rs@@ -407,12 +407,18 @@ pub fn relink(s: &mut Session, p: &Value) -> Result<Value> {Some(MediaRef::File { path }) => path,_ => return Err(bad("media.relink", format!("item {} is not file media", item.0))),};- let c = check_candidate(s, item, &path, &o)?;+ let mut c = check_candidate(s, item, &path, &o)?;if !c.ok && !force {return Err(EngineError::Other(format!("{} doesn't match {}: {}", file_name(&path), file_name(&old), c.problems.join("; "))));}- if c.source.is_none() && s.media.open_file(&path, &*s.services).is_err() {- return Err(EngineError::Other(format!("{path} can't be opened")));+ if c.source.is_none() {+ // Forced past a failed check: the file was never opened for its properties, so do it now+ // and let the item take the new file's own info instead of keeping the old file's.+ let Ok(src) = s.media.open_file(&path, &*s.services) else {+ return Err(EngineError::Other(format!("{path} can't be opened")));+ };+ c.info = Some(src.info().clone());+ c.source = Some(src);}let mut plans = vec![Plan { item, cand: c }];if o.relink_others {diff --git a/crates/engine/src/relink_tests.rs b/crates/engine/src/relink_tests.rsindex 64efe4ba4..b6475c0d4 100644--- a/crates/engine/src/relink_tests.rs+++ b/crates/engine/src/relink_tests.rs@@ -128,6 +128,22 @@ fn fingerprint_mismatch_is_refused_unless_forced() {let _ = std::fs::remove_dir_all(&root);}+#[test]+fn forced_relink_takes_the_new_files_properties() {+ let root = tmp_dir("relink-forced-info");+ let (path, items) = saved_project(&root);+ std::fs::remove_dir_all(root.join("Media")).unwrap();+ // same name, different pictures and a different size+ let other = root.join("Other");+ std::fs::create_dir_all(&other).unwrap();+ make_movie(&other.join("a.mov"), DemoScene::Dunes, W * 2, H * 2, 12);+ let mut s = open(&path);+ s.execute("media.relink", json!({"item": items[0].0, "path": other.join("a.mov").to_string_lossy(), "force": true, "relinkOthers": false})).unwrap();+ let width = s.project.item(items[0]).and_then(|i| i.as_media()).and_then(|m| m.info.video.as_ref().map(|v| v.width));+ assert_eq!(width, Some(W * 2), "the item describes the replacement file");+ let _ = std::fs::remove_dir_all(&root);+}+#[test]fn make_offline_shows_the_slate_until_relinked() {let root = tmp_dir("relink-offline");