Fix minor bugs and cleanup

main
John Kenyon 2025-04-07 04:17:09 +00:00
parent dd3552336f
commit cc76c5b5bd
6 changed files with 21 additions and 19 deletions

View File

@ -9,12 +9,12 @@ use cypraea_common::paths;
use cypraea_common::protocol::{ClientMessage, DaemonMessage}; use cypraea_common::protocol::{ClientMessage, DaemonMessage};
use rustyline::error::ReadlineError; use rustyline::error::ReadlineError;
use rustyline::DefaultEditor; use rustyline::DefaultEditor;
use serde_json::Deserializer; //use serde_json::Deserializer;
use std::io::{self, Write}; use std::io::{self, Write};
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::net::UnixStream; use tokio::net::UnixStream;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tracing::{debug, error, info, warn}; use tracing::{debug, error, info /*,warn*/};
mod display; mod display;
@ -195,7 +195,7 @@ async fn run_repl(
// Wait for the session info response // Wait for the session info response
let mut session_info = None; let mut session_info = None;
if let Some(msg) = rx.recv().await { 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); session_info = Some(info);
} }
} }
@ -276,7 +276,7 @@ async fn run_repl(
send_message(&mut writer, &info_msg).await send_message(&mut writer, &info_msg).await
.context("Failed to send session info message")?; .context("Failed to send session info message")?;
} }
Some(DaemonMessage::SessionInfo { session: info }) => { Some(DaemonMessage::SessionDetails { session: info }) => {
session_info = Some(info); session_info = Some(info);
} }
Some(DaemonMessage::Error { message }) => { Some(DaemonMessage::Error { message }) => {

View File

@ -2,13 +2,13 @@
//! //!
//! This module handles logging command execution and other events to a SQLite database. //! 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 chrono::{DateTime, Utc};
use rusqlite::{params, Connection}; use rusqlite::{params, Connection};
use std::path::Path; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use tokio::sync::Mutex; use tokio::sync::Mutex;
use tracing::{debug, error, info}; use tracing::{debug, /*error,*/ info};
/// Database connection wrapper. /// Database connection wrapper.
#[derive(Clone)] #[derive(Clone)]
@ -109,7 +109,9 @@ impl Database {
], ],
) )
.context("Failed to insert command record")?; .context("Failed to insert command record")?;
if res != 1 {
return Err(anyhow!("Failed to insert command record"));
}
Ok(conn.last_insert_rowid()) Ok(conn.last_insert_rowid())
} }

View File

@ -5,7 +5,7 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser; use clap::Parser;
use tracing::{info, warn, error}; use tracing::{info /*, warn, error*/};
use cypraea_common::paths; use cypraea_common::paths;
mod db; mod db;

View File

@ -3,7 +3,7 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use std::process::Stdio; use std::process::Stdio;
use tokio::io::{AsyncBufReadExt, AsyncRead, BufReader}; use tokio::io::{AsyncBufReadExt, AsyncRead, BufReader};
use tokio::process::{Child, Command}; use tokio::process::{/*Child,*/ Command};
use tokio::sync::mpsc; use tokio::sync::mpsc;
/// Output capture result. /// Output capture result.

View File

@ -4,7 +4,7 @@
//! and command execution within sessions. //! and command execution within sessions.
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use chrono::{DateTime, Duration, Utc}; use chrono::{DateTime, /*Duration,*/ Utc};
use cypraea_common::protocol::SessionInfo; use cypraea_common::protocol::SessionInfo;
use shell_words; use shell_words;
use std::collections::HashMap; use std::collections::HashMap;
@ -12,9 +12,9 @@ use std::path::{Path, PathBuf};
use std::process::Stdio; use std::process::Stdio;
use std::sync::Arc; use std::sync::Arc;
use tokio::io::{AsyncBufReadExt, AsyncRead, BufReader}; use tokio::io::{AsyncBufReadExt, AsyncRead, BufReader};
use tokio::process::{Child, Command}; use tokio::process::{/*Child,*/ Command};
use tokio::sync::{mpsc, Mutex, RwLock}; use tokio::sync::{mpsc, Mutex, RwLock};
use tracing::{debug, error, info, warn}; use tracing::{/*debug,*/ error, info /*, warn*/};
use crate::db::{CommandRecord, Database}; use crate::db::{CommandRecord, Database};
@ -198,8 +198,8 @@ impl Session {
tokio::spawn(stderr_future); tokio::spawn(stderr_future);
// Collect stdout and stderr for logging // Collect stdout and stderr for logging
let mut stdout_buffer = Vec::new(); let stdout_buffer = Vec::new();
let mut stderr_buffer = Vec::new(); let stderr_buffer = Vec::new();
// Wait for the command to finish // Wait for the command to finish
let status = child.wait().await.context("Failed to wait for command")?; let status = child.wait().await.context("Failed to wait for command")?;

View File

@ -4,13 +4,13 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use cypraea_common::protocol::{ClientMessage, DaemonMessage}; use cypraea_common::protocol::{ClientMessage, DaemonMessage};
use serde_json::Deserializer; //use serde_json::Deserializer;
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter}; use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter};
use tokio::net::{UnixListener, UnixStream}; use tokio::net::{UnixListener, UnixStream};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tracing::{debug, error, info, warn}; use tracing::{debug, error, info /*, warn*/};
use crate::session::SessionManager; use crate::session::SessionManager;
@ -217,7 +217,7 @@ async fn process_message(
// Send session info // Send session info
let info = session_guard.get_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")?; tx.send(msg).await.context("Failed to send session info")?;
} }
@ -249,7 +249,7 @@ async fn process_message(
// Send session info // Send session info
let info = session_guard.get_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")?; 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 session_guard = session_arc.lock().await;
let info = session_guard.get_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")?; tx.send(msg).await.context("Failed to send session info")?;
} }
} }