aboutsummaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/common/src/lib.rs2
-rw-r--r--crates/daemon/Cargo.toml1
-rw-r--r--crates/daemon/src/aclient/database/mod.rs24
-rw-r--r--crates/daemon/src/aclient/record/encryption.rs2
-rw-r--r--crates/daemon/src/api/control.rs8
-rw-r--r--crates/daemon/src/main.rs3
-rw-r--r--crates/server/src/database/db/mod.rs5
7 files changed, 27 insertions, 18 deletions
diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs
index 8bd18456..18e3189f 100644
--- a/crates/common/src/lib.rs
+++ b/crates/common/src/lib.rs
@@ -42,7 +42,7 @@ macro_rules! new_uuid {
{
fn encode_by_ref(
&self,
- buf: &mut DB::ArgumentBuffer<'q>,
+ buf: &mut DB::ArgumentBuffer,
) -> Result<sqlx::encode::IsNull, Box<dyn std::error::Error + Send + Sync + 'static>>
{
self.0.encode_by_ref(buf)
diff --git a/crates/daemon/Cargo.toml b/crates/daemon/Cargo.toml
index 2dad72bc..763b3043 100644
--- a/crates/daemon/Cargo.toml
+++ b/crates/daemon/Cargo.toml
@@ -16,7 +16,6 @@ crypto_secretbox = { workspace = true }
dashmap = { workspace = true }
eyre = { workspace = true }
fs-err = { workspace = true }
-fs4 = { workspace = true }
indicatif = { workspace = true }
interim = { workspace = true }
listenfd = { workspace = true }
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()
diff --git a/crates/server/src/database/db/mod.rs b/crates/server/src/database/db/mod.rs
index 9345ff6b..19a1fb3b 100644
--- a/crates/server/src/database/db/mod.rs
+++ b/crates/server/src/database/db/mod.rs
@@ -1,8 +1,7 @@
use std::collections::HashMap;
-use rand::Rng;
-
use crate::database::{DbError, DbResult, DbSettings, models::User};
+use rand::RngExt;
use sqlx::postgres::PgPoolOptions;
use turtle_common::record::{EncryptedData, HostId, Record, RecordIdx, RecordStatus};
@@ -230,7 +229,7 @@ impl ServerPostgres {
let idx_cache_rollout =
std::env::var("IDX_CACHE_ROLLOUT").unwrap_or_else(|_| "0".to_string());
let idx_cache_rollout = idx_cache_rollout.parse::<f64>().unwrap_or(0.0);
- let use_idx_cache = rand::thread_rng().gen_bool(idx_cache_rollout / 100.0);
+ let use_idx_cache = rand::rng().random_bool(idx_cache_rollout / 100.0);
let mut res: Vec<(Uuid, String, i64)> = if use_idx_cache {
tracing::debug!("using idx cache for user {}", user.id);