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.
This commit is contained in:
+1
-1
@@ -152,7 +152,7 @@ struct Opts {
|
||||
#[arg(long)]
|
||||
kernel: Option<PathBuf>,
|
||||
/// 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<u16>,
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -244,7 +244,10 @@ pub fn gc(home: &Path, keep: &[String]) -> Result<u64> {
|
||||
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;
|
||||
|
||||
+2
-2
@@ -88,9 +88,9 @@ fn rows(h: &Path) -> Result<Vec<Row>> {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user