diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-08-22 21:54:12 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-08-22 21:54:12 +0200 |
| commit | 1261fd5d7ff67c907c72fbbd6959d68bd7c8063b (patch) | |
| tree | ce18c0240b0d4fb00bd4d7d1b9829fb0b7d8c152 /crates/daemon/src | |
| parent | treewide: Update Cargo.toml metadata (diff) | |
| download | atuin-1261fd5d7ff67c907c72fbbd6959d68bd7c8063b.zip | |
treewide: Upgrade and update dependencies
`rusty_paseto` was left explicitly on v0.8 because the v0.10 is no longer
compatible with `rusty_paserk`.
Diffstat (limited to 'crates/daemon/src')
| -rw-r--r-- | crates/daemon/src/aclient/database/mod.rs | 24 | ||||
| -rw-r--r-- | crates/daemon/src/aclient/record/encryption.rs | 2 | ||||
| -rw-r--r-- | crates/daemon/src/api/control.rs | 8 | ||||
| -rw-r--r-- | crates/daemon/src/main.rs | 3 |
4 files changed, 24 insertions, 13 deletions
diff --git a/crates/daemon/src/aclient/database/mod.rs b/crates/daemon/src/aclient/database/mod.rs index f24eb777..7cee866e 100644 --- a/crates/daemon/src/aclient/database/mod.rs +++ b/crates/daemon/src/aclient/database/mod.rs @@ -3,7 +3,7 @@ use std::{path::Path, str::FromStr, time::Duration}; use fs_err::{self as fs}; use sql_builder::{SqlBuilder, SqlName}; use sqlx::{ - Result, Row, + AssertSqlSafe, Result, Row, sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePool, SqliteRow, SqliteSynchronous}, }; use time::OffsetDateTime; @@ -56,8 +56,11 @@ impl ClientSqlite { async fn save_raw(tx: &mut sqlx::Transaction<'_, sqlx::Sqlite>, h: &History) -> Result<()> { sqlx::query( - "insert or ignore into history(id, timestamp, duration, exit, command, cwd, session, hostname, author, intent, deleted_at) - values(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)", + " + INSERT OR IGNORE + INTO history (id, timestamp, duration, exit, command, cwd, session, hostname, author, intent, deleted_at) + VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11) + ", ) .bind(h.id.to_string().as_str()) .bind(h.timestamp.unix_timestamp_nanos() as i64) @@ -156,12 +159,16 @@ impl ClientSqlite { } if let Some(max) = max { + let max: usize = max; query.limit(max); } let query = query.sql().expect("bug in list query. please report"); - let res = sqlx::query(&query) + // SAFETY: + // - The query is constructed via sql_bulider, and as such should be safe. + // - The only value, that is directly added to the query is a `usize`. + let res = sqlx::query(AssertSqlSafe(query)) .map(Self::query_history_inner) .fetch_all(&self.pool) .await?; @@ -177,11 +184,16 @@ impl ClientSqlite { debug!("listing history from {:?} to {:?}", from, to); let res = sqlx::query( - "select * from history where timestamp >= ?1 and timestamp <= ?2 order by timestamp asc", + " + SELECT * + FROM history + WHERE timestamp >= ?1 AND timestamp <= ?2 + ORDER BY timestamp ASC + ", ) .bind(from.unix_timestamp_nanos() as i64) .bind(to.unix_timestamp_nanos() as i64) - .map(Self::query_history_inner) + .map(Self::query_history_inner) .fetch_all(&self.pool) .await?; diff --git a/crates/daemon/src/aclient/record/encryption.rs b/crates/daemon/src/aclient/record/encryption.rs index 67f191e9..11de96d5 100644 --- a/crates/daemon/src/aclient/record/encryption.rs +++ b/crates/daemon/src/aclient/record/encryption.rs @@ -2,7 +2,7 @@ use base64::{Engine, engine::general_purpose}; use eyre::{Context, Result, ensure}; use rusty_paserk::{Key, KeyId, Local, PieWrappedKey}; use rusty_paseto::core::{ - ImplicitAssertion, Key as DataKey, Local as LocalPurpose, Paseto, PasetoNonce, Payload, V4, + ImplicitAssertion, Key as DataKey, Local as LocalPurpose, Paseto, PasetoNonce, Payload, V4 }; use serde::{Deserialize, Serialize}; use turtle_common::record::{ diff --git a/crates/daemon/src/api/control.rs b/crates/daemon/src/api/control.rs index 8277f434..16b4bd94 100644 --- a/crates/daemon/src/api/control.rs +++ b/crates/daemon/src/api/control.rs @@ -1,7 +1,7 @@ use std::time::Duration; use eyre::Result; -use rand::Rng; +use rand::RngExt; use tokio::time::{self, MissedTickBehavior}; use tonic::{Request, Response, Status}; use tracing::{Level, instrument}; @@ -149,7 +149,7 @@ async fn sync_loop(handle: DaemonHandle) { let history_store = HistoryStore::new(handle.store().clone(), host_id, encryption_key); // Don't backoff by more than 30 mins (with a random jitter of up to 1 min) - let max_interval: f64 = 60.0f64.mul_add(30.0, rand::thread_rng().gen_range(0.0..60.0)); + let max_interval: f64 = 60.0f64.mul_add(30.0, rand::rng().random_range(0.0..60.0)); let mut ticker = time::interval(Duration::from_secs(settings.daemon.sync_frequency)); @@ -242,8 +242,8 @@ async fn do_sync_tick( }); // Exponential backoff - let mut rng = rand::thread_rng(); - let mut new_interval = ticker.period().as_secs_f64() * rng.gen_range(2.0..2.2); + let mut rng = rand::rng(); + let mut new_interval = ticker.period().as_secs_f64() * rng.random_range(2.0..2.2); if new_interval > max_interval { new_interval = max_interval; diff --git a/crates/daemon/src/main.rs b/crates/daemon/src/main.rs index d157d075..50a41775 100644 --- a/crates/daemon/src/main.rs +++ b/crates/daemon/src/main.rs @@ -13,7 +13,6 @@ use std::{ use clap::Parser; use eyre::WrapErr; use eyre::{Result, bail}; -use fs4::fs_std::FileExt; use tracing_subscriber::EnvFilter; use crate::{ @@ -142,7 +141,7 @@ impl PidfileGuard { fn acquire(path: &Path) -> Result<Self> { let mut file = open_lock_file(path)?; - if !file.try_lock_exclusive()? { + if let Err(fs::TryLockError::WouldBlock) = file.try_lock() { bail!( "daemon already running (pidfile lock busy at {})", path.display() |
