Skip to content

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

#2342: CLI file.exportMedia waits for the export before the process exits

irgendwasmitfelix163fffbefa2b
diff --git a/apps/filmcraft-cli/src/main.rs b/apps/filmcraft-cli/src/main.rs
index b57f1888b..7873e7a0d 100644
--- a/apps/filmcraft-cli/src/main.rs
+++ b/apps/filmcraft-cli/src/main.rs
@@ -169,9 +169,18 @@ impl Backend {
Backend::Local(Box::new(s))
}
- async fn exec(&mut self, id: &str, params: Value) -> Result<Value, String> {
+ async fn exec(&mut self, id: &str, mut params: Value) -> Result<Value, String> {
match self {
- Backend::Local(s) => s.execute(id, params).map_err(|e| e.to_string()),
+ // this process exits after the command, so a background export would never be written:
+ // long commands wait unless the caller says otherwise (#2342)
+ Backend::Local(s) => {
+ if filmcraft_automation::long_job::LONG_COMMANDS.contains(&id)
+ && let Some(p) = params.as_object_mut()
+ {
+ p.entry("wait").or_insert(json!(true));
+ }
+ s.execute(id, params).map_err(|e| e.to_string())
+ }
// a blocking export runs as an app job polled by the client (#91, #92)
Backend::Bridge(b) => b.execute(id, params).await.map_err(|e| e.to_string()),
}
diff --git a/apps/filmcraft-cli/tests/cli.rs b/apps/filmcraft-cli/tests/cli.rs
index d5ded27fa..4c6d8b3ec 100644
--- a/apps/filmcraft-cli/tests/cli.rs
+++ b/apps/filmcraft-cli/tests/cli.rs
@@ -3,7 +3,7 @@
use std::io::Write;
use std::process::{Command, Output, Stdio};
-use serde_json::Value;
+use serde_json::{Value, json};
fn cli(args: &[&str]) -> Output {
Command::new(env!("CARGO_BIN_EXE_filmcraft-cli")).args(args).output().expect("spawn filmcraft-cli")
@@ -150,6 +150,22 @@ fn export_wav_waits_for_job() {
let _ = std::fs::remove_dir_all(&dir);
}
+#[test]
+fn run_waits_for_an_export_on_its_last_line() {
+ // #2342: `file.exportMedia` as the last line of a script is written before `run` exits
+ let dir = std::env::temp_dir().join(format!("fc-cli-run-x-{}", std::process::id()));
+ std::fs::create_dir_all(&dir).unwrap();
+ let out = dir.join("last.wav");
+ let script = json!({"id": "file.exportMedia", "params": {"path": out.to_str().unwrap(), "format": "wav"}}).to_string();
+ let mut child =
+ Command::new(env!("CARGO_BIN_EXE_filmcraft-cli")).args(["--demo", "run", "-"]).stdin(Stdio::piped()).stdout(Stdio::piped()).spawn().unwrap();
+ child.stdin.take().unwrap().write_all(format!("{script}\n").as_bytes()).unwrap();
+ let o = child.wait_with_output().unwrap();
+ assert!(o.status.success(), "{}", String::from_utf8_lossy(&o.stdout));
+ assert!(std::fs::metadata(&out).map(|m| m.len() > 44).unwrap_or(false), "{}", String::from_utf8_lossy(&o.stdout));
+ let _ = std::fs::remove_dir_all(&dir);
+}
+
/// `export --preset`: a built-in preset by name (dash or en dash), a custom range, a user preset
/// from `--data-dir`, `--list-presets`, `--queue`, and a clean failure for an unknown preset.
#[test]