From 8ab77ec9dc8e3faccd0b570c710a8e0658427eb6 Mon Sep 17 00:00:00 2001 From: Niklas Haiden Date: Thu, 22 Oct 2026 19:55:48 +0200 Subject: [PATCH] fix(#8): ps skips corrupt meta, gc tolerates vanished refs, reject -p 0 One corrupt meta.json aborted `wsbx ps`; gc aborted on ENOENT when a concurrent pull replaced a ref file; -p 0 could never work on the host side. --- src/main.rs | 2 +- src/oci.rs | 5 ++++- src/sandbox.rs | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5bfdc0e..d6e919b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -152,7 +152,7 @@ struct Opts { #[arg(long)] kernel: Option, /// Tunnel the host's localhost:PORT to localhost:PORT in the VM (vsock, no network exposure) - #[arg(short = 'p', long = "host-port")] + #[arg(short = 'p', long = "host-port", value_parser = clap::value_parser!(u16).range(1..))] host_ports: Vec, } diff --git a/src/oci.rs b/src/oci.rs index 16fc161..29def78 100644 --- a/src/oci.rs +++ b/src/oci.rs @@ -244,7 +244,10 @@ pub fn gc(home: &Path, keep: &[String]) -> Result { for e in fs::read_dir(home.join("images/refs"))?.flatten() { match fs::read_to_string(e.path()) { Ok(d) if keep.contains(&e.path()) => drop(live.insert(image_dir(home, d.trim()))), - _ => fs::remove_file(e.path())?, + _ => match fs::remove_file(e.path()) { + Err(e) if e.kind() != std::io::ErrorKind::NotFound => return Err(e.into()), // gone: a concurrent pull renamed it + _ => {} + }, } } let mut freed = 0; diff --git a/src/sandbox.rs b/src/sandbox.rs index f311911..fbb9d50 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -88,9 +88,9 @@ fn rows(h: &Path) -> Result> { let Ok(rd) = fs::read_dir(h.join("sandboxes")) else { return Ok(vec![]) }; let mut rows = vec![]; for e in rd.flatten() { - let Ok(m) = fs::read(e.path().join("meta.json")) else { continue }; + let Some(meta) = fs::read(e.path().join("meta.json")).ok().and_then(|m| serde_json::from_slice(&m).ok()) else { continue }; let running = lock_stopped(&e.path()).is_err(); - rows.push(Row { name: e.file_name().to_string_lossy().into(), dir: e.path(), meta: serde_json::from_slice(&m)?, running }); + rows.push(Row { name: e.file_name().to_string_lossy().into(), dir: e.path(), meta, running }); } rows.sort_by(|a, b| a.name.cmp(&b.name)); Ok(rows)