aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-common/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/atuin-common/src/utils.rs')
-rw-r--r--crates/atuin-common/src/utils.rs41
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]