From f75aef9e81269424462647dc243757c224e3bd9b Mon Sep 17 00:00:00 2001 From: robcholz <84130577+robcholz@users.noreply.github.com> Date: Sat, 7 Feb 2026 21:15:09 -0500 Subject: [PATCH] ci: fixed --- src/bin/vibebox.rs | 7 ++-- src/config.rs | 11 +----- src/session_manager.rs | 28 +++++++------- src/vm.rs | 8 ++-- src/vm_manager.rs | 87 ++++++++++++++++++++---------------------- 5 files changed, 63 insertions(+), 78 deletions(-) diff --git a/src/bin/vibebox.rs b/src/bin/vibebox.rs index e3558b0..85469f8 100644 --- a/src/bin/vibebox.rs +++ b/src/bin/vibebox.rs @@ -126,7 +126,7 @@ fn main() -> Result<()> { Ok(()) } -fn handle_command(command: Command, cwd: &PathBuf, config_override: Option<&Path>) -> Result<()> { +fn handle_command(command: Command, cwd: &Path, config_override: Option<&Path>) -> Result<()> { match command { Command::List => { let manager = SessionManager::new()?; @@ -223,7 +223,7 @@ fn handle_command(command: Command, cwd: &PathBuf, config_override: Option<&Path } } -fn project_name(directory: &PathBuf) -> String { +fn project_name(directory: &Path) -> String { directory .file_name() .and_then(|name| name.to_str()) @@ -231,7 +231,7 @@ fn project_name(directory: &PathBuf) -> String { .to_string() } -fn relative_to_home(directory: &PathBuf) -> String { +fn relative_to_home(directory: &Path) -> String { let Ok(home) = env::var("HOME") else { return directory.display().to_string(); }; @@ -323,7 +323,6 @@ fn format_last_active(value: Option<&str>) -> String { if seconds < 0 { seconds = 0; } - let seconds = seconds as i64; let week_seconds = 7 * 24 * 60 * 60; if seconds >= week_seconds { let formatted = diff --git a/src/config.rs b/src/config.rs index 0688c92..014a00b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,22 +14,13 @@ const DEFAULT_CPU_COUNT: usize = 2; const DEFAULT_RAM_MB: u64 = 2048; const DEFAULT_AUTO_SHUTDOWN_MS: u64 = 20000; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct Config { #[serde(rename = "box")] pub box_cfg: BoxConfig, pub supervisor: SupervisorConfig, } -impl Default for Config { - fn default() -> Self { - Self { - box_cfg: BoxConfig::default(), - supervisor: SupervisorConfig::default(), - } - } -} - #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BoxConfig { pub cpu_count: usize, diff --git a/src/session_manager.rs b/src/session_manager.rs index 6359fe5..258d41f 100644 --- a/src/session_manager.rs +++ b/src/session_manager.rs @@ -223,12 +223,12 @@ impl SessionManager { removed += 1; continue; } - if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) { - if stem != record.id { - let _ = fs::remove_file(&path); - removed += 1; - continue; - } + if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) + && stem != record.id + { + let _ = fs::remove_file(&path); + removed += 1; + continue; } sessions.push(record); } @@ -327,15 +327,15 @@ fn read_instance_metadata(directory: &Path) -> Result PathBuf { if let Ok(home) = env::var("HOME") { return PathBuf::from(home).join(stripped); } - } else if value == "~" { - if let Ok(home) = env::var("HOME") { - return PathBuf::from(home); - } + } else if value == "~" + && let Ok(home) = env::var("HOME") + { + return PathBuf::from(home); } PathBuf::from(value) } diff --git a/src/vm_manager.rs b/src/vm_manager.rs index 7af8fd8..4cec32d 100644 --- a/src/vm_manager.rs +++ b/src/vm_manager.rs @@ -170,21 +170,20 @@ fn ensure_pid_file(project_root: &Path) -> Result() { - if pid_is_alive(pid) { - if is_socket_path(&socket_path) { - return Err(format!("vm manager already running (pid {pid})").into()); - } - tracing::warn!( - pid, - path = %socket_path.display(), - "stale pid file detected with missing socket" - ); - } + if let Ok(content) = fs::read_to_string(&pid_path) + && let Ok(pid) = content.trim().parse::() + && pid_is_alive(pid) + { + if is_socket_path(&socket_path) { + return Err(format!("vm manager already running (pid {pid})").into()); } - let _ = fs::remove_file(&pid_path); + tracing::warn!( + pid, + path = %socket_path.display(), + "stale pid file detected with missing socket" + ); } + let _ = fs::remove_file(&pid_path); fs::write(&pid_path, format!("{}\n", std::process::id()))?; let _ = fs::set_permissions(&pid_path, fs::Permissions::from_mode(0o600)); Ok(PidFileGuard { path: pid_path }) @@ -192,12 +191,11 @@ fn ensure_pid_file(project_root: &Path) -> Result() { - if pid_is_alive(pid) { - return; - } - } + if let Ok(content) = fs::read_to_string(&pid_path) + && let Ok(pid) = content.trim().parse::() + && pid_is_alive(pid) + { + return; } let _ = fs::remove_file(&pid_path); } @@ -423,7 +421,7 @@ fn read_client_pid(stream: &UnixStream) -> Option { Ok(0) => break, Ok(n) => { len += n; - if buf[..len].iter().any(|b| *b == b'\n') || len == buf.len() { + if buf[..len].contains(&b'\n') || len == buf.len() { break; } } @@ -467,10 +465,10 @@ fn spawn_manager_io( let mut line_buf = String::new(); let on_output = move |bytes: &[u8]| { - if let Some(log) = &log_for_output { - if let Ok(mut file) = log.lock() { - let _ = file.write_all(bytes); - } + if let Some(log) = &log_for_output + && let Ok(mut file) = log.lock() + { + let _ = file.write_all(bytes); } let text = String::from_utf8_lossy(bytes); @@ -483,17 +481,16 @@ fn spawn_manager_io( } line_buf.drain(..=pos); - let cleaned = line.trim_start_matches(|c: char| c == '\r' || c == ' '); + let cleaned = line.trim_start_matches(['\r', ' ']); if let Some(pos) = cleaned.find("VIBEBOX_IPV4=") { let ip_raw = &cleaned[(pos + "VIBEBOX_IPV4=".len())..]; let ip = extract_ipv4(ip_raw).unwrap_or_default(); - if !ip.is_empty() { - if let Ok(mut cfg) = config_for_output.lock() { - if cfg.vm_ipv4.as_deref() != Some(ip.as_str()) { - cfg.vm_ipv4 = Some(ip.clone()); - let _ = write_instance_config(&instance_path, &cfg); - } - } + if !ip.is_empty() + && let Ok(mut cfg) = config_for_output.lock() + && cfg.vm_ipv4.as_deref() != Some(ip.as_str()) + { + cfg.vm_ipv4 = Some(ip.clone()); + let _ = write_instance_config(&instance_path, &cfg); } } } @@ -583,7 +580,7 @@ impl VmExecutor for RealVmExecutor { instance_dir: PathBuf, vm_input_tx: Arc>>>, ) -> Result<(), Box> { - let result = vm::run_with_args_and_extras( + vm::run_with_args_and_extras( args, |output_monitor, vm_output_fd, vm_input_fd| { let io_ctx = spawn_manager_io( @@ -598,8 +595,7 @@ impl VmExecutor for RealVmExecutor { }, extra_login_actions, extra_shares, - ); - result + ) } } @@ -755,9 +751,7 @@ fn manager_event_loop( shutdown_sent = false; } Ok(ManagerEvent::Dec(pid)) => { - if ref_count > 0 { - ref_count -= 1; - } + ref_count = ref_count.saturating_sub(1); tracing::info!( ref_count, pid = pid.unwrap_or(0), @@ -776,15 +770,16 @@ fn manager_event_loop( break; } Err(mpsc::RecvTimeoutError::Timeout) => { - if let Some(deadline) = shutdown_deadline { - if Instant::now() >= deadline && !shutdown_sent { - if let Some(tx) = vm_input_tx.lock().unwrap().clone() { - let _ = tx.send(VmInput::Bytes(b"systemctl poweroff\n".to_vec())); - } - tracing::info!("shutdown command sent"); - shutdown_sent = true; - shutdown_deadline = None; + if let Some(deadline) = shutdown_deadline + && Instant::now() >= deadline + && !shutdown_sent + { + if let Some(tx) = vm_input_tx.lock().unwrap().clone() { + let _ = tx.send(VmInput::Bytes(b"systemctl poweroff\n".to_vec())); } + tracing::info!("shutdown command sent"); + shutdown_sent = true; + shutdown_deadline = None; } } Err(mpsc::RecvTimeoutError::Disconnected) => break,