From 97f207b771b94c5285faae4810d6eeda1b78926b Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 11 Jun 2026 16:10:29 +0200 Subject: chore(server): Simplify the database support --- crates/turtle/src/atuin_common/utils.rs | 90 +-------------------------------- 1 file changed, 1 insertion(+), 89 deletions(-) (limited to 'crates/turtle/src/atuin_common/utils.rs') diff --git a/crates/turtle/src/atuin_common/utils.rs b/crates/turtle/src/atuin_common/utils.rs index 81eb1178..09718241 100644 --- a/crates/turtle/src/atuin_common/utils.rs +++ b/crates/turtle/src/atuin_common/utils.rs @@ -2,8 +2,6 @@ use std::borrow::Cow; use std::env; use std::path::{Path, PathBuf}; -use eyre::{Result, eyre}; - use base64::prelude::{BASE64_URL_SAFE_NO_PAD, Engine}; use getrandom::getrandom; use uuid::Uuid; @@ -32,10 +30,6 @@ pub(crate) fn uuid_v7() -> Uuid { Uuid::now_v7() } -pub(crate) fn uuid_v4() -> String { - Uuid::new_v4().as_simple().to_string() -} - pub(crate) fn has_git_dir(path: &str) -> bool { let mut gitdir = PathBuf::from(path); gitdir.push(".git"); @@ -128,14 +122,6 @@ pub(crate) fn logs_dir() -> PathBuf { home_dir().join(".atuin").join("logs") } -pub(crate) fn dotfiles_cache_dir() -> PathBuf { - // In most cases, this will be ~/.local/share/atuin/dotfiles/cache - let data_dir = std::env::var("XDG_DATA_HOME") - .map_or_else(|_| home_dir().join(".local").join("share"), PathBuf::from); - - data_dir.join("atuin").join("dotfiles").join("cache") -} - pub(crate) fn get_current_dir() -> String { // Prefer PWD environment variable over cwd if available to better support symbolic links match env::var("PWD") { @@ -182,33 +168,8 @@ pub(crate) trait Escapable: AsRef { } } -pub(crate) fn unquote(s: &str) -> Result { - if s.chars().count() < 2 { - return Err(eyre!("not enough chars")); - } - - let quote = s.chars().next().unwrap(); - - // not quoted, do nothing - if quote != '"' && quote != '\'' && quote != '`' { - return Ok(s.to_string()); - } - - if s.chars().last().unwrap() != quote { - return Err(eyre!("unexpected eof, quotes do not match")); - } - - // removes quote characters - // the sanity checks performed above ensure that the quotes will be ASCII and this will not - // panic - let s = &s[1..s.len() - 1]; - - Ok(s.to_string()) -} - impl> Escapable for T {} -#[expect(unsafe_code)] #[cfg(test)] mod tests { use pretty_assertions::assert_ne; @@ -227,58 +188,9 @@ mod tests { test_data_dir(); } - #[cfg(not(windows))] - fn test_config_dir_xdg() { - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::remove_var("HOME") }; - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::set_var("XDG_CONFIG_HOME", "/home/user/custom_config") }; - assert_eq!( - config_dir(), - PathBuf::from("/home/user/custom_config/atuin") - ); - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::remove_var("XDG_CONFIG_HOME") }; - } - - #[cfg(not(windows))] - fn test_config_dir() { - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::set_var("HOME", "/home/user") }; - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::remove_var("XDG_CONFIG_HOME") }; - - assert_eq!(config_dir(), PathBuf::from("/home/user/.config/atuin")); - - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::remove_var("HOME") }; - } - - #[cfg(not(windows))] - fn test_data_dir_xdg() { - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::remove_var("HOME") }; - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::set_var("XDG_DATA_HOME", "/home/user/custom_data") }; - assert_eq!(data_dir(), PathBuf::from("/home/user/custom_data/atuin")); - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::remove_var("XDG_DATA_HOME") }; - } - - #[cfg(not(windows))] - fn test_data_dir() { - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::set_var("HOME", "/home/user") }; - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::remove_var("XDG_DATA_HOME") }; - assert_eq!(data_dir(), PathBuf::from("/home/user/.local/share/atuin")); - // TODO: Audit that the environment access only happens in single-threaded code. - unsafe { env::remove_var("HOME") }; - } - #[test] fn uuid_is_unique() { - let how_many: usize = 1000000; + let how_many: usize = 1_000_000; // for peace of mind let mut uuids: HashSet = HashSet::with_capacity(how_many); -- cgit v1.3.1