diff options
| author | Ellie Huxtable <ellie@atuin.sh> | 2025-03-19 12:44:20 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-19 12:44:20 +0000 |
| commit | 14ec768b4520d4fc34dbf24e663ea7db940c18b7 (patch) | |
| tree | a37db707ab8676cad5b3e6ca47af3f2997958906 /crates/atuin-common/src/utils.rs | |
| parent | feat: Use readline binding for ctrl-a when it is not the prefix (#2626) (diff) | |
| download | atuin-14ec768b4520d4fc34dbf24e663ea7db940c18b7.zip | |
chore: migrate to rust 2024 (#2635)
* chore: upgrade to 2024 edition
* ugh unsafe
* format
* nixxxxxxxxxxx why
Diffstat (limited to '')
| -rw-r--r-- | crates/atuin-common/src/utils.rs | 41 |
1 files changed, 27 insertions, 14 deletions
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<String> { impl<T: AsRef<str>> 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] |
