forked from extern/nushell
OsString and paths
This commit is contained in:
parent
4a4d8c78fb
commit
e6eedf8824
@ -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<String, String>,
|
||||
pub dirs: IndexMap<OsString, String>,
|
||||
}
|
||||
#[async_trait]
|
||||
impl WholeStreamCommand for Autoenv {
|
||||
|
@ -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");
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user