on main help sign in
ci: fixed
commitf75aef9e81269424462647dc243757c224e3bd9b authorrobcholz <84130577+robcholz@users.noreply.github.com> dateSat 7 Feb 2026, 21:15 (8 months ago) parent9caf438
5 files changed+63−78
src/bin/vibebox.rs+3−4 src/config.rs+1−10 src/session_manager.rs+14−14 src/vm.rs+4−4 src/vm_manager.rs+41−46
src/bin/vibebox.rs+3−4
@@ -126,7 +126,7 @@ fn main() -> Result<()> {
126126 Ok(())
127127}
128128
129−fn handle_command(command: Command, cwd: &PathBuf, config_override: Option<&Path>) -> Result<()> {
129+fn handle_command(command: Command, cwd: &Path, config_override: Option<&Path>) -> Result<()> {
130130 match command {
131131 Command::List => {
132132 let manager = SessionManager::new()?;
@@ -223,7 +223,7 @@ fn handle_command(command: Command, cwd: &PathBuf, config_override: Option<&Path
223223 }
224224}
225225
226−fn project_name(directory: &PathBuf) -> String {
226+fn project_name(directory: &Path) -> String {
227227 directory
228228 .file_name()
229229 .and_then(|name| name.to_str())
@@ -231,7 +231,7 @@ fn project_name(directory: &PathBuf) -> String {
231231 .to_string()
232232}
233233
234−fn relative_to_home(directory: &PathBuf) -> String {
234+fn relative_to_home(directory: &Path) -> String {
235235 let Ok(home) = env::var("HOME") else {
236236 return directory.display().to_string();
237237 };
@@ -323,7 +323,6 @@ fn format_last_active(value: Option<&str>) -> String {
323323 if seconds < 0 {
324324 seconds = 0;
325325 }
326− let seconds = seconds as i64;
327326 let week_seconds = 7 * 24 * 60 * 60;
328327 if seconds >= week_seconds {
329328 let formatted =
src/config.rs+1−10
@@ -14,22 +14,13 @@ const DEFAULT_CPU_COUNT: usize = 2;
1414const DEFAULT_RAM_MB: u64 = 2048;
1515const DEFAULT_AUTO_SHUTDOWN_MS: u64 = 20000;
1616
17−#[derive(Debug, Clone, Serialize, Deserialize)]
17+#[derive(Debug, Clone, Default, Serialize, Deserialize)]
1818pub struct Config {
1919 #[serde(rename = "box")]
2020 pub box_cfg: BoxConfig,
2121 pub supervisor: SupervisorConfig,
2222}
2323
24−impl Default for Config {
25− fn default() -> Self {
26− Self {
27− box_cfg: BoxConfig::default(),
28− supervisor: SupervisorConfig::default(),
29− }
30− }
31−}
32−
3324#[derive(Debug, Clone, Serialize, Deserialize)]
3425pub struct BoxConfig {
3526 pub cpu_count: usize,
src/session_manager.rs+14−14
@@ -223,12 +223,12 @@ impl SessionManager {
223223 removed += 1;
224224 continue;
225225 }
226− if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) {
227− if stem != record.id {
228− let _ = fs::remove_file(&path);
229− removed += 1;
230− continue;
231− }
226+ if let Some(stem) = path.file_stem().and_then(|s| s.to_str())
227+ && stem != record.id
228+ {
229+ let _ = fs::remove_file(&path);
230+ removed += 1;
231+ continue;
232232 }
233233 sessions.push(record);
234234 }
@@ -327,15 +327,15 @@ fn read_instance_metadata(directory: &Path) -> Result<InstanceMetadata, SessionE
327327 }
328328 let raw = fs::read_to_string(&instance_path)?;
329329 let mut meta: InstanceMetadata = toml::from_str(&raw)?;
330− if let Some(id) = &meta.id {
331− if id.trim().is_empty() {
332− meta.id = None;
333− }
330+ if let Some(id) = &meta.id
331+ && id.trim().is_empty()
332+ {
333+ meta.id = None;
334334 }
335− if let Some(last_active) = &meta.last_active {
336− if last_active.trim().is_empty() {
337− meta.last_active = None;
338− }
335+ if let Some(last_active) = &meta.last_active
336+ && last_active.trim().is_empty()
337+ {
338+ meta.last_active = None;
339339 }
340340 Ok(meta)
341341}
src/vm.rs+4−4
@@ -155,10 +155,10 @@ fn expand_tilde_path(value: &str) -> PathBuf {
155155 if let Ok(home) = env::var("HOME") {
156156 return PathBuf::from(home).join(stripped);
157157 }
158− } else if value == "~" {
159− if let Ok(home) = env::var("HOME") {
160− return PathBuf::from(home);
161− }
158+ } else if value == "~"
159+ && let Ok(home) = env::var("HOME")
160+ {
161+ return PathBuf::from(home);
162162 }
163163 PathBuf::from(value)
164164}
src/vm_manager.rs+41−46
@@ -170,21 +170,20 @@ fn ensure_pid_file(project_root: &Path) -> Result<PidFileGuard, Box<dyn std::err
170170 let instance_dir = ensure_instance_dir(project_root)?;
171171 let pid_path = instance_dir.join(VM_MANAGER_PID_NAME);
172172 let socket_path = instance_dir.join(VM_MANAGER_SOCKET_NAME);
173− if let Ok(content) = fs::read_to_string(&pid_path) {
174− if let Ok(pid) = content.trim().parse::<u32>() {
175− if pid_is_alive(pid) {
176− if is_socket_path(&socket_path) {
177− return Err(format!("vm manager already running (pid {pid})").into());
178− }
179− tracing::warn!(
180− pid,
181− path = %socket_path.display(),
182− "stale pid file detected with missing socket"
183− );
184− }
173+ if let Ok(content) = fs::read_to_string(&pid_path)
174+ && let Ok(pid) = content.trim().parse::<u32>()
175+ && pid_is_alive(pid)
176+ {
177+ if is_socket_path(&socket_path) {
178+ return Err(format!("vm manager already running (pid {pid})").into());
185179 }
186− let _ = fs::remove_file(&pid_path);
180+ tracing::warn!(
181+ pid,
182+ path = %socket_path.display(),
183+ "stale pid file detected with missing socket"
184+ );
187185 }
186+ let _ = fs::remove_file(&pid_path);
188187 fs::write(&pid_path, format!("{}\n", std::process::id()))?;
189188 let _ = fs::set_permissions(&pid_path, fs::Permissions::from_mode(0o600));
190189 Ok(PidFileGuard { path: pid_path })
@@ -192,12 +191,11 @@ fn ensure_pid_file(project_root: &Path) -> Result<PidFileGuard, Box<dyn std::err
192191
193192fn cleanup_stale_manager(instance_dir: &Path) {
194193 let pid_path = instance_dir.join(VM_MANAGER_PID_NAME);
195− if let Ok(content) = fs::read_to_string(&pid_path) {
196− if let Ok(pid) = content.trim().parse::<u32>() {
197− if pid_is_alive(pid) {
198− return;
199− }
200− }
194+ if let Ok(content) = fs::read_to_string(&pid_path)
195+ && let Ok(pid) = content.trim().parse::<u32>()
196+ && pid_is_alive(pid)
197+ {
198+ return;
201199 }
202200 let _ = fs::remove_file(&pid_path);
203201}
@@ -423,7 +421,7 @@ fn read_client_pid(stream: &UnixStream) -> Option<u32> {
423421 Ok(0) => break,
424422 Ok(n) => {
425423 len += n;
426− if buf[..len].iter().any(|b| *b == b'\n') || len == buf.len() {
424+ if buf[..len].contains(&b'\n') || len == buf.len() {
427425 break;
428426 }
429427 }
@@ -467,10 +465,10 @@ fn spawn_manager_io(
467465 let mut line_buf = String::new();
468466
469467 let on_output = move |bytes: &[u8]| {
470− if let Some(log) = &log_for_output {
471− if let Ok(mut file) = log.lock() {
472− let _ = file.write_all(bytes);
473− }
468+ if let Some(log) = &log_for_output
469+ && let Ok(mut file) = log.lock()
470+ {
471+ let _ = file.write_all(bytes);
474472 }
475473
476474 let text = String::from_utf8_lossy(bytes);
@@ -483,17 +481,16 @@ fn spawn_manager_io(
483481 }
484482 line_buf.drain(..=pos);
485483
486− let cleaned = line.trim_start_matches(|c: char| c == '\r' || c == ' ');
484+ let cleaned = line.trim_start_matches(['\r', ' ']);
487485 if let Some(pos) = cleaned.find("VIBEBOX_IPV4=") {
488486 let ip_raw = &cleaned[(pos + "VIBEBOX_IPV4=".len())..];
489487 let ip = extract_ipv4(ip_raw).unwrap_or_default();
490− if !ip.is_empty() {
491− if let Ok(mut cfg) = config_for_output.lock() {
492− if cfg.vm_ipv4.as_deref() != Some(ip.as_str()) {
493− cfg.vm_ipv4 = Some(ip.clone());
494− let _ = write_instance_config(&instance_path, &cfg);
495− }
496− }
488+ if !ip.is_empty()
489+ && let Ok(mut cfg) = config_for_output.lock()
490+ && cfg.vm_ipv4.as_deref() != Some(ip.as_str())
491+ {
492+ cfg.vm_ipv4 = Some(ip.clone());
493+ let _ = write_instance_config(&instance_path, &cfg);
497494 }
498495 }
499496 }
@@ -583,7 +580,7 @@ impl VmExecutor for RealVmExecutor {
583580 instance_dir: PathBuf,
584581 vm_input_tx: Arc<Mutex<Option<mpsc::Sender<VmInput>>>>,
585582 ) -> Result<(), Box<dyn std::error::Error>> {
586− let result = vm::run_with_args_and_extras(
583+ vm::run_with_args_and_extras(
587584 args,
588585 |output_monitor, vm_output_fd, vm_input_fd| {
589586 let io_ctx = spawn_manager_io(
@@ -598,8 +595,7 @@ impl VmExecutor for RealVmExecutor {
598595 },
599596 extra_login_actions,
600597 extra_shares,
601− );
602− result
598+ )
603599 }
604600}
605601
@@ -755,9 +751,7 @@ fn manager_event_loop(
755751 shutdown_sent = false;
756752 }
757753 Ok(ManagerEvent::Dec(pid)) => {
758− if ref_count > 0 {
759− ref_count -= 1;
760− }
754+ ref_count = ref_count.saturating_sub(1);
761755 tracing::info!(
762756 ref_count,
763757 pid = pid.unwrap_or(0),
@@ -776,15 +770,16 @@ fn manager_event_loop(
776770 break;
777771 }
778772 Err(mpsc::RecvTimeoutError::Timeout) => {
779− if let Some(deadline) = shutdown_deadline {
780− if Instant::now() >= deadline && !shutdown_sent {
781− if let Some(tx) = vm_input_tx.lock().unwrap().clone() {
782− let _ = tx.send(VmInput::Bytes(b"systemctl poweroff\n".to_vec()));
783− }
784− tracing::info!("shutdown command sent");
785− shutdown_sent = true;
786− shutdown_deadline = None;
773+ if let Some(deadline) = shutdown_deadline
774+ && Instant::now() >= deadline
775+ && !shutdown_sent
776+ {
777+ if let Some(tx) = vm_input_tx.lock().unwrap().clone() {
778+ let _ = tx.send(VmInput::Bytes(b"systemctl poweroff\n".to_vec()));
787779 }
780+ tracing::info!("shutdown command sent");
781+ shutdown_sent = true;
782+ shutdown_deadline = None;
788783 }
789784 }
790785 Err(mpsc::RecvTimeoutError::Disconnected) => break,