fix(#5): write sandbox meta.json before creating the disk

Until meta existed the sandbox's image looked unreferenced, so a concurrent
`wsbx gc` deleted it mid-create; a crashed create was also invisible to ps and
refused by rm.
This commit is contained in:
2026-10-22 19:53:03 +02:00
parent 37c58cb5b2
commit 2231e4efe1
+2 -1
View File
@@ -76,9 +76,10 @@ pub fn run(h: &Path, o: Opts, image: &str, cmd: Vec<String>, extra: &[String], g
} }
if !disk.exists() { if !disk.exists() {
eprintln!("wsbx: creating sandbox {name}"); eprintln!("wsbx: creating sandbox {name}");
create_disk(h, &disk, o.disk)?; // meta first: it marks the image as in use for `wsbx gc` and makes a crashed create visible to ps/rm
meta = json!({"image": image, "digest": img.digest, "workspace": ws, "created": now(), "provisioned": false}); meta = json!({"image": image, "digest": img.digest, "workspace": ws, "created": now(), "provisioned": false});
fs::write(&meta_path, serde_json::to_vec_pretty(&meta)?)?; fs::write(&meta_path, serde_json::to_vec_pretty(&meta)?)?;
create_disk(h, &disk, o.disk)?;
} }
// Build the guest-side run script (executed as root by init, then drops to the image user). // Build the guest-side run script (executed as root by init, then drops to the image user).