From 7f0574a1a5c078033e7e62f9535b63d6c2b3de24 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Wed, 20 May 2026 11:27:25 +0200 Subject: [PATCH] fix: create remote directories before syncing --- p/src/commands/run.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/p/src/commands/run.rs b/p/src/commands/run.rs index 5ba0790..36f93f4 100644 --- a/p/src/commands/run.rs +++ b/p/src/commands/run.rs @@ -34,7 +34,23 @@ pub fn execute(worker_name: Option<&str>, cmd: Vec, no_sync: bool) -> Re .context("directory sync failed")?; } - // ── 2. Save local job record ────────────────────────────────────────────── + // ── 1. Create remote directories ───────────────────────────────────────── + // Must happen before sync so rsync has a destination to write into. + + ssh::run_capture(&worker, &format!("mkdir -p {} {}", job_dir, work_dir)) + .context("failed to create remote directories")?; + + // ── 2. Sync directory ───────────────────────────────────────────────────── + + if no_sync { + eprintln!("Skipping sync (--no-sync)."); + } else { + eprintln!("Syncing to {}...", worker.name); + sync::push_dir(&worker, &std::env::current_dir()?, &work_dir) + .context("directory sync failed")?; + } + + // ── 3. Save local job record ────────────────────────────────────────────── // Written before touching the remote so that `p ls` shows the job as // running even if we lose the connection immediately after. @@ -50,21 +66,19 @@ pub fn execute(worker_name: Option<&str>, cmd: Vec, no_sync: bool) -> Re }; db::save(&job)?; - // ── 3. Write files and start the job on the worker ──────────────────────── + // ── 4. Write files and start the job on the worker ──────────────────────── let cmd_b64 = B64.encode(&cmd_str); let run_sh = build_run_sh(&session, &job_dir, &work_dir, &worker.name); let run_sh_b64 = B64.encode(&run_sh); let setup = format!( - "mkdir -p {job_dir} {work_dir} && \ - printf '%s' '{cmd_b64}' > {job_dir}/cmd && \ + "printf '%s' '{cmd_b64}' > {job_dir}/cmd && \ printf '%s' '{run_sh_b64}' | base64 -d > {job_dir}/run.sh && \ chmod +x {job_dir}/run.sh && \ date +%s > {job_dir}/started_at && \ tmux new-session -d -s '{session}' {job_dir}/run.sh", job_dir = job_dir, - work_dir = work_dir, cmd_b64 = cmd_b64, run_sh_b64 = run_sh_b64, session = session,