fix: executor .tmp output handling clobbered fresh script results
run_with_frames / run_with_output_idx / run_with_output_idx_and_frames had an inverted .tmp-file flow: 1. Before spawning, if the final .json existed it was renamed to .json.tmp (the OLD output set aside as "tmp"). 2. The script was passed the FINAL .json path, so it wrote fresh data there. 3. On success, .json.tmp (the OLD/empty file) was renamed back OVER the fresh .json, discarding the new result. For face clustering this meant the freshly-clustered 2-person result was always overwritten by the stale/empty previous face_cluster.json, so the cluster agent reported "0 clusters" and Face Deduplication matched nothing. Fix: remove the bogus pre-rename and instead pass the .tmp path to the script as its output argument, then promote .tmp -> .json only on success. This guarantees the fresh result is what lands in the final file. Applied identically to all three run_* helpers. Verified on 9cbeb112 (FilmRiot): cluster-agent now returns 2 clusters / 17 traces and face_cluster.json contains the real clustering (was 0).
This commit is contained in:
@@ -298,11 +298,6 @@ impl PythonExecutor {
|
||||
tmp.set_extension("json.tmp");
|
||||
tmp
|
||||
});
|
||||
if let (Some(src), Some(dst)) = (&output_path, &tmp_path) {
|
||||
if src.exists() {
|
||||
let _ = std::fs::rename(src, dst);
|
||||
}
|
||||
}
|
||||
|
||||
let mut cmd = Command::new(&self.python_path);
|
||||
cmd.env("MOMENTRY_OUTPUT_DIR", &*OUTPUT_DIR);
|
||||
@@ -321,7 +316,16 @@ impl PythonExecutor {
|
||||
}
|
||||
cmd.arg(&script_path);
|
||||
|
||||
for arg in args {
|
||||
for (i, arg) in args.iter().enumerate() {
|
||||
// Route the script's declared output path through a .tmp file so the
|
||||
// fresh result is written there and promoted to the real path only on
|
||||
// success (avoids clobbering good output with a stale/partial file).
|
||||
if i == output_idx {
|
||||
if let Some(ref tmp) = tmp_path {
|
||||
cmd.arg(tmp);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
@@ -446,11 +450,6 @@ impl PythonExecutor {
|
||||
tmp.set_extension("json.tmp");
|
||||
tmp
|
||||
});
|
||||
if let (Some(src), Some(dst)) = (&output_path, &tmp_path) {
|
||||
if src.exists() {
|
||||
let _ = std::fs::rename(src, dst);
|
||||
}
|
||||
}
|
||||
|
||||
let mut cmd = Command::new(&self.python_path);
|
||||
cmd.env("MOMENTRY_OUTPUT_DIR", &*OUTPUT_DIR);
|
||||
@@ -469,7 +468,16 @@ impl PythonExecutor {
|
||||
}
|
||||
cmd.arg(&script_path);
|
||||
|
||||
for arg in args {
|
||||
for (i, arg) in args.iter().enumerate() {
|
||||
// Route the script's declared output path through a .tmp file so the
|
||||
// fresh result is written there and promoted to the real path only on
|
||||
// success (avoids clobbering good output with a stale/partial file).
|
||||
if i == output_idx {
|
||||
if let Some(ref tmp) = tmp_path {
|
||||
cmd.arg(tmp);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
@@ -634,11 +642,6 @@ impl PythonExecutor {
|
||||
tmp.set_extension("json.tmp");
|
||||
tmp
|
||||
});
|
||||
if let (Some(src), Some(dst)) = (&output_path, &tmp_path) {
|
||||
if src.exists() {
|
||||
let _ = std::fs::rename(src, dst);
|
||||
}
|
||||
}
|
||||
|
||||
let mut cmd = Command::new(&self.python_path);
|
||||
cmd.env("MOMENTRY_OUTPUT_DIR", &*OUTPUT_DIR);
|
||||
@@ -654,7 +657,16 @@ impl PythonExecutor {
|
||||
}
|
||||
cmd.arg(&script_path);
|
||||
|
||||
for arg in args {
|
||||
for (i, arg) in args.iter().enumerate() {
|
||||
// Route the script's declared output path through a .tmp file so the
|
||||
// fresh result is written there and promoted to the real path only on
|
||||
// success (avoids clobbering good output with a stale/partial file).
|
||||
if i == output_idx {
|
||||
if let Some(ref tmp) = tmp_path {
|
||||
cmd.arg(tmp);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user