diff --git a/crates/nu-cli/src/commands/autoenv.rs b/crates/nu-cli/src/commands/autoenv.rs index f8ec280f8..0c1c03e62 100644 --- a/crates/nu-cli/src/commands/autoenv.rs +++ b/crates/nu-cli/src/commands/autoenv.rs @@ -4,12 +4,13 @@ use nu_errors::ShellError; use nu_protocol::{ReturnSuccess, UntaggedValue, Signature}; use serde::Deserialize; use serde::Serialize; +use std::ffi::OsString; pub struct Autoenv; #[derive(Deserialize, Serialize)] pub struct Allowed { - pub dirs: IndexMap, + pub dirs: IndexMap, } #[async_trait] impl WholeStreamCommand for Autoenv { diff --git a/crates/nu-cli/src/commands/autoenv_trust.rs b/crates/nu-cli/src/commands/autoenv_trust.rs index 3b2c20ad6..ef80fc655 100644 --- a/crates/nu-cli/src/commands/autoenv_trust.rs +++ b/crates/nu-cli/src/commands/autoenv_trust.rs @@ -6,7 +6,7 @@ use nu_protocol::SyntaxShape; use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value}; use std::hash::{Hash, Hasher}; use std::io::Read; -use std::{collections::hash_map::DefaultHasher, fs, path::PathBuf}; +use std::{collections::hash_map::DefaultHasher, ffi::OsStr, fs, path::PathBuf}; pub struct AutoenvTrust; #[async_trait] @@ -33,12 +33,12 @@ impl WholeStreamCommand for AutoenvTrust { Some(Value { value: UntaggedValue::Primitive(Primitive::String(ref path)), tag: _, - }) => path.clone(), - _ => std::env::current_dir()?.to_string_lossy().to_string(), + }) => PathBuf::from(path), + _ => std::env::current_dir()?, }; let mut env_file_to_allow = dir_to_allow.clone(); - env_file_to_allow.push_str("/.nu-env"); + env_file_to_allow.push(".nu-env"); let content = std::fs::read_to_string(env_file_to_allow)?; let mut hasher = DefaultHasher::new(); content.hash(&mut hasher); @@ -67,7 +67,7 @@ impl WholeStreamCommand for AutoenvTrust { }); allowed .dirs - .insert(dir_to_allow, hasher.finish().to_string()); + .insert(dir_to_allow.as_os_str(), hasher.finish().to_string()); fs::write(config_path, toml::to_string(&allowed).unwrap()) .expect("Couldn't write to toml file"); diff --git a/crates/nu-cli/src/commands/autoenv_untrust.rs b/crates/nu-cli/src/commands/autoenv_untrust.rs index 139bf2281..252e78b0c 100644 --- a/crates/nu-cli/src/commands/autoenv_untrust.rs +++ b/crates/nu-cli/src/commands/autoenv_untrust.rs @@ -34,9 +34,10 @@ impl WholeStreamCommand for AutoenvUnTrust { Some(Value { value: UntaggedValue::Primitive(Primitive::String(ref path)), tag: _, - }) => path.clone(), - _ => std::env::current_dir()?.to_string_lossy().to_string(), + }) => PathBuf::from(path), + _ => std::env::current_dir()?, }; + let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?; let mut file = match std::fs::OpenOptions::new()