From 14ec768b4520d4fc34dbf24e663ea7db940c18b7 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Wed, 19 Mar 2025 12:44:20 +0000 Subject: chore: migrate to rust 2024 (#2635) * chore: upgrade to 2024 edition * ugh unsafe * format * nixxxxxxxxxxx why --- crates/atuin-common/src/utils.rs | 41 ++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'crates/atuin-common/src/utils.rs') diff --git a/crates/atuin-common/src/utils.rs b/crates/atuin-common/src/utils.rs index d495de36..9a84c31b 100644 --- a/crates/atuin-common/src/utils.rs +++ b/crates/atuin-common/src/utils.rs @@ -2,9 +2,9 @@ use std::borrow::Cow; use std::env; use std::path::PathBuf; -use eyre::{eyre, Result}; +use eyre::{Result, eyre}; -use base64::prelude::{Engine, BASE64_URL_SAFE_NO_PAD}; +use base64::prelude::{BASE64_URL_SAFE_NO_PAD, Engine}; use getrandom::getrandom; use uuid::Uuid; @@ -194,6 +194,7 @@ pub fn unquote(s: &str) -> Result { impl> Escapable for T {} +#[allow(unsafe_code)] #[cfg(test)] mod tests { use pretty_assertions::assert_ne; @@ -214,36 +215,48 @@ mod tests { } fn test_config_dir_xdg() { - env::remove_var("HOME"); - env::set_var("XDG_CONFIG_HOME", "/home/user/custom_config"); + // 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") ); - env::remove_var("XDG_CONFIG_HOME"); + // TODO: Audit that the environment access only happens in single-threaded code. + unsafe { env::remove_var("XDG_CONFIG_HOME") }; } fn test_config_dir() { - env::set_var("HOME", "/home/user"); - env::remove_var("XDG_CONFIG_HOME"); + // 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")); - env::remove_var("HOME"); + // TODO: Audit that the environment access only happens in single-threaded code. + unsafe { env::remove_var("HOME") }; } fn test_data_dir_xdg() { - env::remove_var("HOME"); - env::set_var("XDG_DATA_HOME", "/home/user/custom_data"); + // 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")); - env::remove_var("XDG_DATA_HOME"); + // TODO: Audit that the environment access only happens in single-threaded code. + unsafe { env::remove_var("XDG_DATA_HOME") }; } fn test_data_dir() { - env::set_var("HOME", "/home/user"); - env::remove_var("XDG_DATA_HOME"); + // 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")); - env::remove_var("HOME"); + // TODO: Audit that the environment access only happens in single-threaded code. + unsafe { env::remove_var("HOME") }; } #[test] -- cgit v1.3.1