mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-28 14:08:40 -08:00
Overwriting a render no longer freezes the app on projects with many footage files (#3330)
* #3328: output guard checks file identity only where an alias is possible The output guard opened every footage file of the project, for every check of an output that existed, on the UI thread: minutes for long sequences on a network share. It now compares only the files that can be the output (folders on the output's volume, folders holding symbolic links), keeps the identities it learnt in the session (folders that changed are looked at again; Reload Footage forgets them), and does no file system call while its lock is held. render.frame checks and writes with one guard. A control request whose sender stopped waiting is not run, and one tick runs control requests for at most a tenth of a second; the rest follow in order on the next ticks. * #3328: output guard compares paths only, no file is opened Comparing file identities still cost a file open per footage frame when folders were on the output's volume, and caching them invited races (#3330 review). The guard now compares paths by name once resolved: absolute, dot segments resolved, one separator, Windows verbatim prefixes as the plain path, without case on Windows and macOS. A link or hard link to footage under another name is no longer recognised; the reported data loss (#1743) is the same-path case. Render queue duplicate outputs compare by name too. * #3328: drop the link identity tests of the render queue; test and doc review fixes * #3328: a mapped network drive and its UNC path are one place On Windows the output guard resolves each drive letter's root once per guard (std::fs::canonicalize of `X:\`) and compares a path on that letter as the place it resolves to: a mapped network drive as its \server\share path, a subst drive as its folder. A root that can't be resolved keeps its letter. * #3328: drive roots are looked up only where they can matter, and kept a minute A drive letter's root is resolved only when the output and the protected files are not all on one letter, or not all UNC paths: footage and output on one mapped drive never wait for a disconnected drive or an empty removable one. Resolved roots, failures too, are kept process-wide for 60 s. * #3328: the 13,000-frame guard test counts file system lookups instead of timing them * #3328: note why only Windows counts lookups in the 13,000-frame guard test * #3328: queued outputs collide under drive and UNC spellings * #3328: queued sequences and subst drives compare by the place they name * #3328: queued outputs keep their resolved places instead of resolving per comparison * #3328: cache_bench's play request carries the abandoned flag (main's example met the new ControlRequest field) * Refuse an output in a folder linked to a source's folder An output whose name matches no protected file now has its folder resolved on disk, once per folder per guard, and is compared again by name. An output in render-alias/, a symbolic link or junction to plates/, no longer replaces plates/source.exr. No protected file is looked at. * Resolve both folders, and only for a source with the output's file name The footage path as imported may itself run through a link (macOS /var is /private/var, Windows 8.3 names), so resolving only the output's folder missed it. Now an output whose path matches nothing is compared again only with sources of the same file name, both folders resolved once per guard. An output named like no source asks the file system nothing.
This commit is contained in:
1 parent
ffc0ad89da
commit
7e7118f1a5
14 files changed
+1186
-258
No files matched your search
@@ -58,9 +58,14 @@ fn serve(stream: TcpStream, tx: &Sender<ControlRequest>, ctx: &egui::Context) {
|
||||
let Ok(read) = stream.try_clone() else { return };
|
||||
serve_lines(read, stream, |method, params| {
|
||||
let (req, rrx) = ControlRequest::new(method, params);
|
||||
let abandoned = req.abandoned.clone();
|
||||
tx.send(req).ok()?;
|
||||
ctx.request_repaint();
|
||||
Some(rrx.recv_timeout(Duration::from_secs(60)).unwrap_or_else(|_| json!({"ok": false, "error": "timeout"})))
|
||||
Some(rrx.recv_timeout(Duration::from_secs(60)).unwrap_or_else(|_| {
|
||||
// Nobody waits for it any more: the UI doesn't run it if it hasn't begun (#3328).
|
||||
abandoned.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
json!({"ok": false, "error": "timeout"})
|
||||
}))
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ pub use doc_state::{CompSelection, EditorState, KeyClip, KeyMove, KeyRef, LinkCl
|
||||
pub use error::{EngineError, Result};
|
||||
pub use event::Event;
|
||||
pub use fonts::{FontRow, font_features, font_menu, font_preview, font_styles, text_families};
|
||||
pub use output_guard::OutputGuard;
|
||||
pub use services::{FsServices, Importer, PCRAFT_MAX_INPUT, Services, pcraft_too_large};
|
||||
pub use session::upgrade_effects;
|
||||
|
||||
@@ -282,6 +283,9 @@ pub struct Session {
|
||||
/// is, settings that guard what scripts may do can't change (see
|
||||
/// [`prefs::Scripting::same_permissions`]).
|
||||
pub script_calls: ScriptCalls,
|
||||
/// Output guards built so far ([`Session::output_guard`]; a command checks all the files it
|
||||
/// writes with one, #3328).
|
||||
pub output_guards: std::sync::atomic::AtomicU64,
|
||||
}
|
||||
|
||||
/// The count behind [`Session::running_for_script`]; only the engine changes it.
|
||||
@@ -411,6 +415,7 @@ impl Default for Session {
|
||||
aux_footage: None,
|
||||
aux_needs: None,
|
||||
script_calls: ScriptCalls::default(),
|
||||
output_guards: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1023
-158
File diff suppressed because it is too large.
Load diff
@@ -157,35 +157,6 @@ impl Drop for Fixture {
|
||||
}
|
||||
}
|
||||
|
||||
fn link(target: &Path, link: &Path) -> std::io::Result<()> {
|
||||
#[cfg(unix)]
|
||||
return std::os::unix::fs::symlink(target, link);
|
||||
#[cfg(windows)]
|
||||
return std::os::windows::fs::symlink_file(target, link);
|
||||
#[cfg(not(any(unix, windows)))]
|
||||
{
|
||||
let _ = (target, link);
|
||||
Err(std::io::ErrorKind::Unsupported.into())
|
||||
}
|
||||
}
|
||||
|
||||
/// A folder that leads to `target`: a symbolic link, or on Windows, where that takes a privilege
|
||||
/// most accounts lack, a junction.
|
||||
fn link_dir(target: &Path, link: &Path) -> std::io::Result<()> {
|
||||
#[cfg(unix)]
|
||||
return std::os::unix::fs::symlink(target, link);
|
||||
#[cfg(windows)]
|
||||
return std::os::windows::fs::symlink_dir(target, link).or_else(|_| {
|
||||
let made = std::process::Command::new("cmd").args(["/C", "mklink", "/J"]).arg(link).arg(target).output()?;
|
||||
if made.status.success() { Ok(()) } else { Err(std::io::Error::other(String::from_utf8_lossy(&made.stdout).into_owned())) }
|
||||
});
|
||||
#[cfg(not(any(unix, windows)))]
|
||||
{
|
||||
let _ = (target, link);
|
||||
Err(std::io::ErrorKind::Unsupported.into())
|
||||
}
|
||||
}
|
||||
|
||||
/// The report: save a new project beside `footage.mp4`, import it, make a composition from it
|
||||
/// (it is named after the file), add that to the Render Queue and click Render. The composition's
|
||||
/// default output is `<project folder>/footage.mp4`, the footage itself.
|
||||
@@ -482,44 +453,8 @@ fn a_sequence_that_skips_existing_frames_needs_no_flag() {
|
||||
assert_eq!(f.read("render_00002.png"), RENDERED);
|
||||
}
|
||||
|
||||
/// A link is another name for the file it points to.
|
||||
#[test]
|
||||
fn a_link_to_the_footage_is_the_footage() {
|
||||
let mut f = Fixture::new("link");
|
||||
f.footage("clip.mov");
|
||||
f.comp("Main");
|
||||
let alias = f.path("render.mov");
|
||||
if link(&f.path("clip.mov"), &alias).is_err() {
|
||||
eprintln!("this account cannot make symbolic links: skipped");
|
||||
return;
|
||||
}
|
||||
f.s.execute("renderQueue.add", json!({"format": "prores", "output": f.text("render.mov")})).unwrap();
|
||||
let e = f.render(json!({"overwrite": true})).unwrap_err().to_string();
|
||||
assert!(e.contains("render.mov") && e.contains("footage"), "{e}");
|
||||
assert_eq!(f.read("clip.mov"), SOURCE);
|
||||
assert!(std::fs::symlink_metadata(&alias).unwrap().file_type().is_symlink(), "the link was not replaced either");
|
||||
}
|
||||
|
||||
/// A hard link to the footage under another name is the same file on disk: replacing it would truncate the footage.
|
||||
#[test]
|
||||
fn a_hard_link_to_the_footage_is_the_footage() {
|
||||
let mut f = Fixture::new("hardlink");
|
||||
f.footage("clip.mov");
|
||||
f.comp("Main");
|
||||
if std::fs::hard_link(f.path("clip.mov"), f.path("render.mov")).is_err() {
|
||||
eprintln!("this volume cannot make hard links: skipped");
|
||||
return;
|
||||
}
|
||||
f.s.execute("renderQueue.add", json!({"format": "prores", "output": f.text("render.mov")})).unwrap();
|
||||
// not even with overwrite
|
||||
let e = f.render(json!({"overwrite": true})).unwrap_err().to_string();
|
||||
assert!(e.contains("render.mov") && e.contains("footage"), "{e}");
|
||||
assert_eq!(f.read("clip.mov"), SOURCE);
|
||||
assert_eq!(f.read("render.mov"), SOURCE, "the other name still leads to the footage");
|
||||
assert!(f.exported().is_empty(), "nothing was rendered");
|
||||
}
|
||||
|
||||
/// A copy of the footage has its size and bytes, but it is another file: an earlier render may replace it.
|
||||
/// (A link to footage under another name is not recognised: paths are compared, #3328.)
|
||||
#[test]
|
||||
fn a_copy_of_the_footage_is_not_the_footage() {
|
||||
let mut f = Fixture::new("copy");
|
||||
@@ -532,26 +467,6 @@ fn a_copy_of_the_footage_is_not_the_footage() {
|
||||
assert_eq!(f.read("clip.mov"), SOURCE, "the footage is as it was");
|
||||
}
|
||||
|
||||
/// Footage imported through a linked folder is the same file as the one in the real folder.
|
||||
#[test]
|
||||
fn footage_reached_through_a_linked_folder_is_still_footage() {
|
||||
let mut f = Fixture::new("linked-folder");
|
||||
std::fs::create_dir_all(f.path("real")).unwrap();
|
||||
std::fs::write(f.path("real").join("clip.mov"), SOURCE).unwrap();
|
||||
if link_dir(&f.path("real"), &f.path("linked")).is_err() {
|
||||
eprintln!("this account cannot link folders: skipped");
|
||||
return;
|
||||
}
|
||||
let via_link =
|
||||
Footage { path: f.path("linked").join("clip.mov").to_string_lossy().into_owned(), kind: FootageKind::Video, has_video: true, ..Default::default() };
|
||||
Arc::make_mut(&mut f.s.project).add_item("clip.mov", Label::None, None, ItemKind::Footage(via_link));
|
||||
f.comp("Main");
|
||||
f.s.execute("renderQueue.add", json!({"format": "prores", "output": f.path("real").join("clip.mov").to_string_lossy()})).unwrap();
|
||||
let e = f.render(json!({"overwrite": true})).unwrap_err().to_string();
|
||||
assert!(e.contains("footage"), "{e}");
|
||||
assert_eq!(std::fs::read(f.path("real").join("clip.mov")).unwrap(), SOURCE);
|
||||
}
|
||||
|
||||
/// Where the volume ignores case, `CLIP.MOV` is `clip.mov`.
|
||||
#[test]
|
||||
fn another_spelling_of_the_footage_name_is_the_footage_where_the_volume_ignores_case() {
|
||||
|
||||
@@ -251,7 +251,7 @@ fn play(session: effectcraft_engine::Session, cid: ItemId, secs: f64, gpu: bool)
|
||||
}
|
||||
h.state().frames.clear();
|
||||
let (reply, _r) = std::sync::mpsc::channel();
|
||||
let _ = tx.send(ControlRequest { method: "ui.playback".into(), params: json!({"action": "play"}), reply });
|
||||
let _ = tx.send(ControlRequest { method: "ui.playback".into(), params: json!({"action": "play"}), reply, abandoned: Default::default() });
|
||||
let t0 = Instant::now();
|
||||
let (mut started, mut stalled, mut last, mut scales) = (None, 0.0, t0, std::collections::BTreeMap::<u32, u64>::new());
|
||||
// When each new frame went on screen (seconds since play was pressed): the cadence. The
|
||||
|
||||
@@ -135,7 +135,7 @@ fn main() {
|
||||
continue;
|
||||
}
|
||||
let (reply_tx, reply_rx) = mpsc::channel();
|
||||
let _ = tx.send(ControlRequest { method: method.clone(), params, reply: reply_tx });
|
||||
let _ = tx.send(ControlRequest { method: method.clone(), params, reply: reply_tx, abandoned: Default::default() });
|
||||
// Requests are answered on a later frame (some wait for input to be processed).
|
||||
let deadline = Instant::now() + Duration::from_secs(10);
|
||||
let reply = loop {
|
||||
|
||||
@@ -3,6 +3,11 @@ use super::hooks::Hooks;
|
||||
use super::state::{FrameWindow, PlaybackPass, ShotTarget};
|
||||
use super::*;
|
||||
|
||||
/// How long one tick runs control requests before the window paints again
|
||||
/// ([`EffectcraftApp::control_budget`]): a tenth of a second, so a script's quick requests run
|
||||
/// in one tick and a backlog of slow ones still lets the window answer.
|
||||
const CONTROL_BUDGET: std::time::Duration = std::time::Duration::from_millis(100);
|
||||
|
||||
mod clipboard;
|
||||
mod files;
|
||||
mod frame;
|
||||
@@ -66,6 +71,8 @@ impl EffectcraftApp {
|
||||
last_viewer_scale: None,
|
||||
control_rx: None,
|
||||
deferred: vec![],
|
||||
control_backlog: vec![],
|
||||
control_budget: CONTROL_BUDGET,
|
||||
synthetic: vec![],
|
||||
forwarded: ForwardedInput::default(),
|
||||
input_waiters: vec![],
|
||||
|
||||
@@ -18,13 +18,31 @@ impl EffectcraftApp {
|
||||
/// through `control::handle`, answer `Done` immediately, retry `Retry` until its three-second deadline, hold
|
||||
/// input/job/screenshot replies until their event happens and finish job waiters. Retry timeouts and refused
|
||||
/// screenshots are answered as `{"ok": false, "error": ...}`; the receiver is kept for the next tick.
|
||||
///
|
||||
/// A request its sender no longer waits for ([`ControlRequest::is_abandoned`]) is dropped
|
||||
/// unrun. Once [`EffectcraftApp::control_budget`] is spent, the rest wait for the next tick
|
||||
/// in their order, ahead of the retries and new requests (#3328: a backlog of slow requests
|
||||
/// kept the window from painting until all had run).
|
||||
fn drain_control(&mut self, ctx: &egui::Context, now: f64) {
|
||||
let Some(rx) = self.control_rx.take() else { return };
|
||||
let mut reqs: Vec<(ControlRequest, f64)> = std::mem::take(&mut self.deferred);
|
||||
let mut reqs: Vec<(ControlRequest, Option<f64>)> = std::mem::take(&mut self.control_backlog);
|
||||
reqs.extend(std::mem::take(&mut self.deferred).into_iter().map(|(req, deadline)| (req, Some(deadline))));
|
||||
while let Ok(req) = rx.try_recv() {
|
||||
reqs.push((req, now + 3.0));
|
||||
reqs.push((req, None));
|
||||
}
|
||||
let started = web_time::Instant::now();
|
||||
let mut ran = 0usize;
|
||||
for (req, deadline) in reqs {
|
||||
if req.is_abandoned() {
|
||||
continue;
|
||||
}
|
||||
if ran > 0 && started.elapsed() >= self.control_budget {
|
||||
self.control_backlog.push((req, deadline));
|
||||
continue;
|
||||
}
|
||||
ran += 1;
|
||||
// (a request's three seconds of retries count from when it first ran)
|
||||
let deadline = deadline.unwrap_or(now + 3.0);
|
||||
let reply = req.reply.clone();
|
||||
match control::handle(self, ctx, &req, now) {
|
||||
control::Outcome::Done(v) => {
|
||||
@@ -65,6 +83,9 @@ impl EffectcraftApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
if !self.control_backlog.is_empty() {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
self.control_rx = Some(rx);
|
||||
self.finish_job_waiters(ctx);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ pub struct ControlRequest {
|
||||
pub method: String,
|
||||
pub params: Value,
|
||||
pub reply: Sender<Value>,
|
||||
/// Set by whoever sent it once nobody waits for the reply any more (the control server's
|
||||
/// timeout): a request not begun by then is not run (#3328: requests that had timed out ran
|
||||
/// later, one after another, and a client that went on sending kept the window busy).
|
||||
pub abandoned: Arc<std::sync::atomic::AtomicBool>,
|
||||
}
|
||||
|
||||
impl ControlRequest {
|
||||
@@ -44,7 +48,12 @@ impl ControlRequest {
|
||||
/// receive the UI thread's reply.
|
||||
pub fn new(method: impl Into<String>, params: Value) -> (Self, std::sync::mpsc::Receiver<Value>) {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
(Self { method: method.into(), params, reply: tx }, rx)
|
||||
(Self { method: method.into(), params, reply: tx, abandoned: Default::default() }, rx)
|
||||
}
|
||||
|
||||
/// Whether the sender stopped waiting for the reply ([`ControlRequest::abandoned`]).
|
||||
pub fn is_abandoned(&self) -> bool {
|
||||
self.abandoned.load(std::sync::atomic::Ordering::SeqCst)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -756,9 +765,11 @@ fn quit(app: &mut EffectcraftApp, ctx: &egui::Context, p: &Value) -> Outcome {
|
||||
/// temp file) or inline as base64 when `base64: true`. `write: true` with `base64: true` does both.
|
||||
fn render_frame(app: &EffectcraftApp, p: &Value) -> Outcome {
|
||||
let s = &app.session;
|
||||
// A file the project reads is never the output (checked before rendering).
|
||||
// A file the project reads is never the output (checked before rendering, and the write
|
||||
// after it uses the same guard: it looks at the project's files once, #3328).
|
||||
let guard = s.output_guard();
|
||||
if let Some(path) = p.get("path").and_then(Value::as_str)
|
||||
&& let Err(e) = s.refuse_export(path)
|
||||
&& let Err(e) = guard.refuse(path)
|
||||
{
|
||||
return err(e);
|
||||
}
|
||||
@@ -792,7 +803,7 @@ fn render_frame(app: &EffectcraftApp, p: &Value) -> Outcome {
|
||||
if inline {
|
||||
out["png"] = json!(base64(&png));
|
||||
}
|
||||
match s.write_output(&path, &png) {
|
||||
match s.write_output_guarded(&guard, &path, &png) {
|
||||
Ok(()) => {
|
||||
out["path"] = json!(path);
|
||||
ok(out)
|
||||
|
||||
@@ -386,6 +386,12 @@ pub struct EffectcraftApp {
|
||||
last_viewer_scale: Option<f64>,
|
||||
pub(crate) control_rx: Option<Receiver<ControlRequest>>,
|
||||
pub(crate) deferred: Vec<(ControlRequest, f64)>,
|
||||
/// Requests a tick left to the next one when it ran out of [`EffectcraftApp::control_budget`],
|
||||
/// in the order they came, with their retry deadline once they ran (#3328).
|
||||
pub(crate) control_backlog: Vec<(ControlRequest, Option<f64>)>,
|
||||
/// How long one tick runs control requests before it leaves the rest to the next tick (the
|
||||
/// window paints in between). It always runs one.
|
||||
pub(crate) control_budget: std::time::Duration,
|
||||
pub(crate) synthetic: Vec<egui::Event>,
|
||||
/// Input from floating panels' own OS windows for the main window's next frame.
|
||||
pub(crate) forwarded: ForwardedInput,
|
||||
|
||||
@@ -86,6 +86,76 @@ fn a_control_command_that_needs_no_ui_completes_without_a_pass() {
|
||||
assert_eq!(app.ui_passes(), 0);
|
||||
}
|
||||
|
||||
/// A `comp.new` request named `name`, sent on `tx`; its reply, and its abandoned flag.
|
||||
fn queue_comp(
|
||||
tx: &std::sync::mpsc::Sender<ControlRequest>,
|
||||
name: &str,
|
||||
) -> (std::sync::mpsc::Receiver<serde_json::Value>, std::sync::Arc<std::sync::atomic::AtomicBool>) {
|
||||
let (request, reply) =
|
||||
ControlRequest::new("engine.execute", json!({"command": "comp.new", "params": {"name": name, "width": 8, "height": 8, "duration": 1}}));
|
||||
let abandoned = request.abandoned.clone();
|
||||
tx.send(request).unwrap();
|
||||
(reply, abandoned)
|
||||
}
|
||||
|
||||
/// The names of the project's comps, oldest first.
|
||||
fn comp_names(app: &EffectcraftApp) -> Vec<String> {
|
||||
app.session.project.items.values().filter(|i| i.as_comp().is_some()).map(|i| i.name.clone()).collect()
|
||||
}
|
||||
|
||||
fn has_comp(app: &EffectcraftApp, name: &str) -> bool {
|
||||
comp_names(app).iter().any(|n| n == name)
|
||||
}
|
||||
|
||||
/// #3328: a request whose sender stopped waiting (the control server's timeout) before it ran
|
||||
/// is not run; the ones around it are.
|
||||
#[test]
|
||||
fn a_control_request_nobody_waits_for_is_not_run() {
|
||||
let ctx = egui::Context::default();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
app.control_rx = Some(rx);
|
||||
let (first, _) = queue_comp(&tx, "Before");
|
||||
let (gone, abandoned) = queue_comp(&tx, "Abandoned");
|
||||
abandoned.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
let (last, _) = queue_comp(&tx, "After");
|
||||
hidden_tick(&mut app, &ctx, &frame);
|
||||
assert!(has_comp(&app, "Before") && has_comp(&app, "After"));
|
||||
assert!(!has_comp(&app, "Abandoned"), "the abandoned request did not run");
|
||||
assert!(gone.try_recv().is_err(), "and is not answered");
|
||||
assert_eq!(first.try_recv().unwrap()["ok"], true);
|
||||
assert_eq!(last.try_recv().unwrap()["ok"], true);
|
||||
}
|
||||
|
||||
/// #3328: once a tick's time for control requests is spent, the rest run on the next ticks,
|
||||
/// in their order, ahead of requests that came later; the window paints in between.
|
||||
#[test]
|
||||
fn control_requests_over_a_ticks_budget_wait_for_the_next_tick_in_order() {
|
||||
let ctx = egui::Context::default();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
app.control_budget = std::time::Duration::ZERO;
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
app.control_rx = Some(rx);
|
||||
let names = ["One", "Two", "Three"];
|
||||
let replies: Vec<_> = names.iter().map(|n| queue_comp(&tx, n).0).collect();
|
||||
hidden_tick(&mut app, &ctx, &frame);
|
||||
assert!(has_comp(&app, "One") && !has_comp(&app, "Two"), "one request per tick at a zero budget");
|
||||
assert_eq!(app.control_backlog.len(), 2);
|
||||
let (later, _) = queue_comp(&tx, "Later");
|
||||
hidden_tick(&mut app, &ctx, &frame);
|
||||
assert!(has_comp(&app, "Two") && !has_comp(&app, "Three") && !has_comp(&app, "Later"), "the backlog first");
|
||||
hidden_tick(&mut app, &ctx, &frame);
|
||||
hidden_tick(&mut app, &ctx, &frame);
|
||||
assert!(has_comp(&app, "Three") && has_comp(&app, "Later"));
|
||||
let order: Vec<String> = comp_names(&app).into_iter().filter(|n| names.contains(&n.as_str()) || n == "Later").collect();
|
||||
assert_eq!(order, ["One", "Two", "Three", "Later"]);
|
||||
for reply in replies.iter().chain([&later]) {
|
||||
assert_eq!(reply.try_recv().unwrap()["ok"], true);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pass_that_cannot_draw_receives_no_synthetic_input() {
|
||||
let ctx = headless();
|
||||
|
||||
@@ -97,6 +97,19 @@ fn render_frame_never_writes_over_a_file_the_project_reads() {
|
||||
assert_eq!(v["result"]["png"].as_str(), Some(control::base64(&r.read("inline.png")).as_str()));
|
||||
}
|
||||
|
||||
/// #3328: `render.frame` over an existing file checks the project's files once, before the
|
||||
/// render, and writes with that check (it looked at every footage frame twice).
|
||||
#[test]
|
||||
fn render_frame_over_an_existing_file_checks_the_project_once() {
|
||||
let mut r = Rig::new("render-frame-once");
|
||||
std::fs::write(r.dir.join("frame.png"), b"an older frame").unwrap();
|
||||
let before = r.h.state().session.output_guards.load(std::sync::atomic::Ordering::Relaxed);
|
||||
let v = r.reply("render.frame", json!({"path": r.text("frame.png")}));
|
||||
assert_eq!(v["ok"], true, "{v}");
|
||||
assert_eq!(&r.read("frame.png")[..8], b"\x89PNG\r\n\x1a\n", "replaced");
|
||||
assert_eq!(r.h.state().session.output_guards.load(std::sync::atomic::Ordering::Relaxed) - before, 1, "one guard");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn screenshot_never_writes_over_a_file_the_project_reads() {
|
||||
let mut r = Rig::new("screenshot");
|
||||
|
||||
@@ -23,7 +23,9 @@ someone closes that box.
|
||||
- **Reply:** `{"id": 1, "ok": true, "result": ...}` or `{"id": 1, "ok": false, "error": "message"}`.
|
||||
- Requests run on the UI thread between frames. Input methods (`ui.click`, `ui.key` and similar)
|
||||
reply after the synthetic input has been processed. Methods that need an element that isn't drawn
|
||||
yet are retried for a few frames. A request times out after 60 s.
|
||||
yet are retried for a few frames. A request times out after 60 s; one that hasn't begun by then
|
||||
is not run. Requests run until a tenth of a second has passed in one frame, and the rest wait
|
||||
for the next frames in their order, so the window keeps drawing.
|
||||
- **Only requests are read:** every line must be a JSON object with a string `method` (blank lines are
|
||||
skipped). Anything else (text that isn't JSON, a JSON array or number, an object without `method`,
|
||||
invalid UTF-8, a line longer than 4 MiB) gets one error reply ending in "closing the connection", and
|
||||
|
||||
@@ -116,10 +116,18 @@ project file. It checks every output module and segment before dispatching the i
|
||||
item is marked Failed with its reason; other valid queued items can still render. Render logs
|
||||
are checked too. No render parameter overrides this protection.
|
||||
|
||||
Checks compare normalized paths and native file identities, so an existing symbolic link,
|
||||
hard link, junction or Windows short name cannot disguise a source as another output file.
|
||||
Source identities are indexed once per check and matching identities are verified. The index
|
||||
does not keep file handles open for the lifetime of a long sequence.
|
||||
Checks compare paths by name once resolved: made absolute, `.` and `..` resolved, either
|
||||
separator, a Windows verbatim prefix (`\\?\`) as the plain path, and without case on Windows and
|
||||
macOS. No source file is opened, so a check costs the same for a sequence of thousands of frames
|
||||
on a network share. When an output's path matches no source but a source has the same file name,
|
||||
the output's folder and that source's folder are resolved on disk (each folder once per check) and
|
||||
compared again, so a folder reached through a symbolic link or junction, on either side, does not
|
||||
get around the check. On Windows a mapped network drive and its UNC path (`P:\` and
|
||||
`\\server\share\`) are one place, and so are a `subst` drive and its folder. A drive letter's root
|
||||
is looked up only when the output and the sources are not all on one letter, or not all UNC
|
||||
paths, and what it resolves to is kept for a minute. A file-level symbolic link or hard link to a
|
||||
source under another name is not recognised, nor another Unicode normalization of its name on
|
||||
macOS. The check runs before the render starts; a link changed after it is not seen.
|
||||
|
||||
Default output names move aside when they would replace a protected file. This also applies to
|
||||
Create Proxy: recreating a proxy chooses a new default name and attaches the new proxy, leaving
|
||||
|
||||
Reference in new issue
Block a user