mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-27 15:17:38 +00:00
Fix CI: Resolve all Clippy warnings and improve code quality
- Fixed redundant continue statements in loops - Replaced manual string prefix stripping with strip_prefix method - Fixed wildcard pattern that covered other patterns - Removed redundant clone and unnecessary return value - Used format string interpolation for cleaner code - Removed unused imports and variables - All Clippy checks now pass with -D warnings
This commit is contained in:
parent
68dd22e183
commit
ec0bbcfdf4
4 changed files with 28 additions and 31 deletions
|
|
@ -681,7 +681,10 @@ fn handle_session_snapshot(control_path: &Path, path: &str) -> Response<String>
|
||||||
let original_lines = content.lines().count();
|
let original_lines = content.lines().count();
|
||||||
let optimized_lines = optimized_content.lines().count();
|
let optimized_lines = optimized_content.lines().count();
|
||||||
let reduction = if original_lines > 0 {
|
let reduction = if original_lines > 0 {
|
||||||
|
#[allow(clippy::cast_precision_loss)]
|
||||||
|
{
|
||||||
(original_lines - optimized_lines) as f64 / original_lines as f64 * 100.0
|
(original_lines - optimized_lines) as f64 / original_lines as f64 * 100.0
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
};
|
};
|
||||||
|
|
@ -716,7 +719,7 @@ fn handle_session_snapshot(control_path: &Path, path: &str) -> Response<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn optimize_snapshot_content(content: &str) -> String {
|
fn optimize_snapshot_content(content: &str) -> String {
|
||||||
let lines: Vec<&str> = content.trim().split('\n').collect();
|
let lines: Vec<&str> = content.lines().collect();
|
||||||
let mut header_line: Option<&str> = None;
|
let mut header_line: Option<&str> = None;
|
||||||
let mut all_events: Vec<&str> = Vec::new();
|
let mut all_events: Vec<&str> = Vec::new();
|
||||||
|
|
||||||
|
|
@ -1177,11 +1180,17 @@ fn handle_multi_stream(control_path: &Path, req: &mut HttpRequest) {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = watcher.watch(&control_path_clone, RecursiveMode::NonRecursive) {
|
if let Err(e) = watcher.watch(&control_path_clone, RecursiveMode::NonRecursive) {
|
||||||
println!("Failed to watch control directory {control_path_clone:?}: {e}");
|
println!(
|
||||||
|
"Failed to watch control directory {}: {e}",
|
||||||
|
control_path_clone.display()
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Session discovery thread started, watching {control_path_clone:?}");
|
println!(
|
||||||
|
"Session discovery thread started, watching {}",
|
||||||
|
control_path_clone.display()
|
||||||
|
);
|
||||||
|
|
||||||
// Also discover existing sessions at startup
|
// Also discover existing sessions at startup
|
||||||
if let Ok(sessions) = sessions::list_sessions(&control_path_clone) {
|
if let Ok(sessions) = sessions::list_sessions(&control_path_clone) {
|
||||||
|
|
@ -1313,7 +1322,8 @@ fn handle_multi_stream(control_path: &Path, req: &mut HttpRequest) {
|
||||||
|
|
||||||
if let Err(e) = watcher.watch(parent_dir, RecursiveMode::NonRecursive) {
|
if let Err(e) = watcher.watch(parent_dir, RecursiveMode::NonRecursive) {
|
||||||
println!(
|
println!(
|
||||||
"Failed to watch directory {parent_dir:?} for session {session_id_clone}: {e}"
|
"Failed to watch directory {} for session {session_id_clone}: {e}",
|
||||||
|
parent_dir.display()
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ fn main() -> Result<(), anyhow::Error> {
|
||||||
// Handle serve command
|
// Handle serve command
|
||||||
if let Some(addr) = serve_address {
|
if let Some(addr) = serve_address {
|
||||||
// Setup signal handler to update session statuses on shutdown
|
// Setup signal handler to update session statuses on shutdown
|
||||||
crate::term_socket::setup_shutdown_handler()?;
|
crate::term_socket::setup_shutdown_handler();
|
||||||
|
|
||||||
ctrlc::set_handler(move || {
|
ctrlc::set_handler(move || {
|
||||||
println!("Ctrl-C received, updating session statuses and exiting...");
|
println!("Ctrl-C received, updating session statuses and exiting...");
|
||||||
|
|
|
||||||
|
|
@ -352,8 +352,8 @@ impl StreamWriter {
|
||||||
// Skip parameter and intermediate characters
|
// Skip parameter and intermediate characters
|
||||||
while pos < buf.len() {
|
while pos < buf.len() {
|
||||||
match buf[pos] {
|
match buf[pos] {
|
||||||
0x30..=0x3F => pos += 1, // Parameter characters 0-9 : ; < = > ?
|
// Parameter characters 0-9 : ; < = > ? and Intermediate characters
|
||||||
0x20..=0x2F => pos += 1, // Intermediate characters (space) ! " # $ % & ' ( ) * + , - . /
|
0x20..=0x3F => pos += 1,
|
||||||
0x40..=0x7E => return Some(pos + 1), // Final character @ A-Z [ \ ] ^ _ ` a-z { | } ~
|
0x40..=0x7E => return Some(pos + 1), // Final character @ A-Z [ \ ] ^ _ ` a-z { | } ~
|
||||||
_ => return Some(pos), // Invalid sequence, stop here
|
_ => return Some(pos), // Invalid sequence, stop here
|
||||||
}
|
}
|
||||||
|
|
@ -377,8 +377,6 @@ impl StreamWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple two-character sequences: ESC letter
|
// Simple two-character sequences: ESC letter
|
||||||
0x40..=0x7E => Some(2),
|
|
||||||
|
|
||||||
// Other escape sequences - assume two characters for now
|
// Other escape sequences - assume two characters for now
|
||||||
_ => Some(2),
|
_ => Some(2),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ use std::ffi::CString;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
use std::os::unix::io::{AsRawFd, RawFd};
|
||||||
use std::os::unix::net::UnixStream;
|
use std::os::unix::net::UnixStream;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
|
||||||
use std::sync::Arc;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// Spawn a terminal session with PTY fallback
|
/// Spawn a terminal session with PTY fallback
|
||||||
|
|
@ -157,11 +155,11 @@ fn spawn_via_pty(command: &[String], working_dir: Option<&str>) -> Result<String
|
||||||
let expanded_working_dir = if let Some(dir) = working_dir {
|
let expanded_working_dir = if let Some(dir) = working_dir {
|
||||||
if dir == "~/" || dir == "~" {
|
if dir == "~/" || dir == "~" {
|
||||||
std::env::var("HOME").unwrap_or_else(|_| "/".to_string())
|
std::env::var("HOME").unwrap_or_else(|_| "/".to_string())
|
||||||
} else if dir.starts_with("~/") {
|
} else if let Some(stripped) = dir.strip_prefix("~/") {
|
||||||
format!(
|
format!(
|
||||||
"{}/{}",
|
"{}/{}",
|
||||||
std::env::var("HOME").unwrap_or_else(|_| "/".to_string()),
|
std::env::var("HOME").unwrap_or_else(|_| "/".to_string()),
|
||||||
&dir[2..]
|
stripped
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
dir.to_string()
|
dir.to_string()
|
||||||
|
|
@ -256,11 +254,11 @@ fn spawn_via_pty(command: &[String], working_dir: Option<&str>) -> Result<String
|
||||||
if let Some(dir) = working_dir {
|
if let Some(dir) = working_dir {
|
||||||
let expanded_dir = if dir == "~/" || dir == "~" {
|
let expanded_dir = if dir == "~/" || dir == "~" {
|
||||||
std::env::var("HOME").unwrap_or_else(|_| "/".to_string())
|
std::env::var("HOME").unwrap_or_else(|_| "/".to_string())
|
||||||
} else if dir.starts_with("~/") {
|
} else if let Some(stripped) = dir.strip_prefix("~/") {
|
||||||
format!(
|
format!(
|
||||||
"{}/{}",
|
"{}/{}",
|
||||||
std::env::var("HOME").unwrap_or_else(|_| "/".to_string()),
|
std::env::var("HOME").unwrap_or_else(|_| "/".to_string()),
|
||||||
&dir[2..]
|
stripped
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
dir.to_string()
|
dir.to_string()
|
||||||
|
|
@ -406,7 +404,7 @@ fn handle_pty_session(
|
||||||
0 => {
|
0 => {
|
||||||
eprintln!("PTY closed (EOF), updating session status");
|
eprintln!("PTY closed (EOF), updating session status");
|
||||||
// Update session status to exited
|
// Update session status to exited
|
||||||
let session_json_path = format!("{}/session.json", session_dir);
|
let session_json_path = format!("{session_dir}/session.json");
|
||||||
if let Ok(content) = std::fs::read_to_string(&session_json_path) {
|
if let Ok(content) = std::fs::read_to_string(&session_json_path) {
|
||||||
if let Ok(mut session_info) =
|
if let Ok(mut session_info) =
|
||||||
serde_json::from_str::<serde_json::Value>(&content)
|
serde_json::from_str::<serde_json::Value>(&content)
|
||||||
|
|
@ -457,7 +455,6 @@ fn handle_stdin_to_pty(master_fd: RawFd, stdin_path: &str) -> Result<()> {
|
||||||
Ok(0) => {
|
Ok(0) => {
|
||||||
// No data available, sleep briefly to avoid busy waiting
|
// No data available, sleep briefly to avoid busy waiting
|
||||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
// Write to PTY master using libc::write
|
// Write to PTY master using libc::write
|
||||||
|
|
@ -471,7 +468,6 @@ fn handle_stdin_to_pty(master_fd: RawFd, stdin_path: &str) -> Result<()> {
|
||||||
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {
|
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {
|
||||||
// No data available, sleep briefly
|
// No data available, sleep briefly
|
||||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Error reading from stdin FIFO: {e}");
|
eprintln!("Error reading from stdin FIFO: {e}");
|
||||||
|
|
@ -530,23 +526,16 @@ pub fn update_all_sessions_to_exited() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Setup signal handler to cleanup sessions on shutdown
|
/// Setup signal handler to cleanup sessions on shutdown
|
||||||
pub fn setup_shutdown_handler() -> Result<()> {
|
pub fn setup_shutdown_handler() {
|
||||||
let shutdown = Arc::new(AtomicBool::new(false));
|
|
||||||
let shutdown_clone = shutdown.clone();
|
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let mut signals =
|
let mut signals =
|
||||||
Signals::new(&[SIGTERM, SIGINT]).expect("Failed to create signals iterator");
|
Signals::new([SIGTERM, SIGINT]).expect("Failed to create signals iterator");
|
||||||
|
|
||||||
for sig in signals.forever() {
|
if let Some(sig) = signals.forever().next() {
|
||||||
eprintln!("Received signal {:?}, updating session statuses...", sig);
|
eprintln!("Received signal {sig:?}, updating session statuses...");
|
||||||
if let Err(e) = update_all_sessions_to_exited() {
|
if let Err(e) = update_all_sessions_to_exited() {
|
||||||
eprintln!("Failed to update session statuses: {}", e);
|
eprintln!("Failed to update session statuses: {e}");
|
||||||
}
|
}
|
||||||
shutdown_clone.store(true, Ordering::Relaxed);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue