Skip to content

Commit e6eedf8

Browse files
committed
OsString and paths
1 parent 4a4d8c7 commit e6eedf8

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

crates/nu-cli/src/commands/autoenv.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ use nu_errors::ShellError;
44
use nu_protocol::{ReturnSuccess, UntaggedValue, Signature};
55
use serde::Deserialize;
66
use serde::Serialize;
7+
use std::ffi::OsString;
78

89
pub struct Autoenv;
910

1011
#[derive(Deserialize, Serialize)]
1112
pub struct Allowed {
12-
pub dirs: IndexMap<String, String>,
13+
pub dirs: IndexMap<OsString, String>,
1314
}
1415
#[async_trait]
1516
impl WholeStreamCommand for Autoenv {

crates/nu-cli/src/commands/autoenv_trust.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use nu_protocol::SyntaxShape;
66
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
77
use std::hash::{Hash, Hasher};
88
use std::io::Read;
9-
use std::{collections::hash_map::DefaultHasher, fs, path::PathBuf};
9+
use std::{collections::hash_map::DefaultHasher, ffi::OsStr, fs, path::PathBuf};
1010
pub struct AutoenvTrust;
1111

1212
#[async_trait]
@@ -33,12 +33,12 @@ impl WholeStreamCommand for AutoenvTrust {
3333
Some(Value {
3434
value: UntaggedValue::Primitive(Primitive::String(ref path)),
3535
tag: _,
36-
}) => path.clone(),
37-
_ => std::env::current_dir()?.to_string_lossy().to_string(),
36+
}) => PathBuf::from(path),
37+
_ => std::env::current_dir()?,
3838
};
3939

4040
let mut env_file_to_allow = dir_to_allow.clone();
41-
env_file_to_allow.push_str("/.nu-env");
41+
env_file_to_allow.push(".nu-env");
4242
let content = std::fs::read_to_string(env_file_to_allow)?;
4343
let mut hasher = DefaultHasher::new();
4444
content.hash(&mut hasher);
@@ -67,7 +67,7 @@ impl WholeStreamCommand for AutoenvTrust {
6767
});
6868
allowed
6969
.dirs
70-
.insert(dir_to_allow, hasher.finish().to_string());
70+
.insert(dir_to_allow.as_os_str(), hasher.finish().to_string());
7171

7272
fs::write(config_path, toml::to_string(&allowed).unwrap())
7373
.expect("Couldn't write to toml file");

crates/nu-cli/src/commands/autoenv_untrust.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ impl WholeStreamCommand for AutoenvUnTrust {
3434
Some(Value {
3535
value: UntaggedValue::Primitive(Primitive::String(ref path)),
3636
tag: _,
37-
}) => path.clone(),
38-
_ => std::env::current_dir()?.to_string_lossy().to_string(),
37+
}) => PathBuf::from(path),
38+
_ => std::env::current_dir()?,
3939
};
40+
4041
let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?;
4142

4243
let mut file = match std::fs::OpenOptions::new()

0 commit comments

Comments
 (0)