From cc76c5b5bd05562c575067ee07f98c0905fd6719 Mon Sep 17 00:00:00 2001 From: John Kenyon Date: Mon, 7 Apr 2025 04:17:09 +0000 Subject: [PATCH] Fix minor bugs and cleanup --- client/src/main.rs | 8 ++++---- daemon/src/db/mod.rs | 8 +++++--- daemon/src/main.rs | 2 +- daemon/src/session/command.rs | 2 +- daemon/src/session/mod.rs | 10 +++++----- daemon/src/socket/mod.rs | 10 +++++----- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/client/src/main.rs b/client/src/main.rs index d8eb2c8..2e4841b 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -9,12 +9,12 @@ use cypraea_common::paths; use cypraea_common::protocol::{ClientMessage, DaemonMessage}; use rustyline::error::ReadlineError; use rustyline::DefaultEditor; -use serde_json::Deserializer; +//use serde_json::Deserializer; use std::io::{self, Write}; use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; use tokio::net::UnixStream; use tokio::sync::mpsc; -use tracing::{debug, error, info, warn}; +use tracing::{debug, error, info /*,warn*/}; mod display; @@ -195,7 +195,7 @@ async fn run_repl( // Wait for the session info response let mut session_info = None; if let Some(msg) = rx.recv().await { - if let DaemonMessage::SessionInfo { session: info } = msg { + if let DaemonMessage::SessionDetails { session: info } = msg { session_info = Some(info); } } @@ -276,7 +276,7 @@ async fn run_repl( send_message(&mut writer, &info_msg).await .context("Failed to send session info message")?; } - Some(DaemonMessage::SessionInfo { session: info }) => { + Some(DaemonMessage::SessionDetails { session: info }) => { session_info = Some(info); } Some(DaemonMessage::Error { message }) => { diff --git a/daemon/src/db/mod.rs b/daemon/src/db/mod.rs index 46d5762..2b3c227 100644 --- a/daemon/src/db/mod.rs +++ b/daemon/src/db/mod.rs @@ -2,13 +2,13 @@ //! //! This module handles logging command execution and other events to a SQLite database. -use anyhow::{Context, Result}; +use anyhow::{anyhow, Context, Result}; use chrono::{DateTime, Utc}; use rusqlite::{params, Connection}; use std::path::Path; use std::sync::Arc; use tokio::sync::Mutex; -use tracing::{debug, error, info}; +use tracing::{debug, /*error,*/ info}; /// Database connection wrapper. #[derive(Clone)] @@ -109,7 +109,9 @@ impl Database { ], ) .context("Failed to insert command record")?; - + if res != 1 { + return Err(anyhow!("Failed to insert command record")); + } Ok(conn.last_insert_rowid()) } diff --git a/daemon/src/main.rs b/daemon/src/main.rs index 37b0ca3..5738da7 100644 --- a/daemon/src/main.rs +++ b/daemon/src/main.rs @@ -5,7 +5,7 @@ use anyhow::{Context, Result}; use clap::Parser; -use tracing::{info, warn, error}; +use tracing::{info /*, warn, error*/}; use cypraea_common::paths; mod db; diff --git a/daemon/src/session/command.rs b/daemon/src/session/command.rs index 9ae3d38..ddbc05b 100644 --- a/daemon/src/session/command.rs +++ b/daemon/src/session/command.rs @@ -3,7 +3,7 @@ use anyhow::{Context, Result}; use std::process::Stdio; use tokio::io::{AsyncBufReadExt, AsyncRead, BufReader}; -use tokio::process::{Child, Command}; +use tokio::process::{/*Child,*/ Command}; use tokio::sync::mpsc; /// Output capture result. diff --git a/daemon/src/session/mod.rs b/daemon/src/session/mod.rs index 016e97e..4475103 100644 --- a/daemon/src/session/mod.rs +++ b/daemon/src/session/mod.rs @@ -4,7 +4,7 @@ //! and command execution within sessions. use anyhow::{anyhow, Context, Result}; -use chrono::{DateTime, Duration, Utc}; +use chrono::{DateTime, /*Duration,*/ Utc}; use cypraea_common::protocol::SessionInfo; use shell_words; use std::collections::HashMap; @@ -12,9 +12,9 @@ use std::path::{Path, PathBuf}; use std::process::Stdio; use std::sync::Arc; use tokio::io::{AsyncBufReadExt, AsyncRead, BufReader}; -use tokio::process::{Child, Command}; +use tokio::process::{/*Child,*/ Command}; use tokio::sync::{mpsc, Mutex, RwLock}; -use tracing::{debug, error, info, warn}; +use tracing::{/*debug,*/ error, info /*, warn*/}; use crate::db::{CommandRecord, Database}; @@ -198,8 +198,8 @@ impl Session { tokio::spawn(stderr_future); // Collect stdout and stderr for logging - let mut stdout_buffer = Vec::new(); - let mut stderr_buffer = Vec::new(); + let stdout_buffer = Vec::new(); + let stderr_buffer = Vec::new(); // Wait for the command to finish let status = child.wait().await.context("Failed to wait for command")?; diff --git a/daemon/src/socket/mod.rs b/daemon/src/socket/mod.rs index 65c0b88..a6c9b1a 100644 --- a/daemon/src/socket/mod.rs +++ b/daemon/src/socket/mod.rs @@ -4,13 +4,13 @@ use anyhow::{Context, Result}; use cypraea_common::protocol::{ClientMessage, DaemonMessage}; -use serde_json::Deserializer; +//use serde_json::Deserializer; use std::fs; use std::path::Path; use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter}; use tokio::net::{UnixListener, UnixStream}; use tokio::sync::mpsc; -use tracing::{debug, error, info, warn}; +use tracing::{debug, error, info /*, warn*/}; use crate::session::SessionManager; @@ -217,7 +217,7 @@ async fn process_message( // Send session info let info = session_guard.get_info(); - let msg = DaemonMessage::SessionInfo { session: info }; + let msg = DaemonMessage::SessionDetails { session: info }; tx.send(msg).await.context("Failed to send session info")?; } @@ -249,7 +249,7 @@ async fn process_message( // Send session info let info = session_guard.get_info(); - let msg = DaemonMessage::SessionInfo { session: info }; + let msg = DaemonMessage::SessionDetails { session: info }; tx.send(msg).await.context("Failed to send session info")?; } @@ -290,7 +290,7 @@ async fn process_message( let session_guard = session_arc.lock().await; let info = session_guard.get_info(); - let msg = DaemonMessage::SessionInfo { session: info }; + let msg = DaemonMessage::SessionDetails { session: info }; tx.send(msg).await.context("Failed to send session info")?; } }