mirror of
https://github.com/nushell/nushell.git
synced 2025-05-19 01:10:48 +02:00
Fix path
This commit is contained in:
parent
15a8e26664
commit
a77c8d01fa
@ -1,6 +1,6 @@
|
|||||||
use super::autoenv::Allowed;
|
use super::{autoenv::Allowed, cd::CdArgs};
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::prelude::*;
|
use crate::{path, prelude::*};
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::SyntaxShape;
|
use nu_protocol::SyntaxShape;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
||||||
@ -29,17 +29,24 @@ impl WholeStreamCommand for AutoenvTrust {
|
|||||||
registry: &CommandRegistry,
|
registry: &CommandRegistry,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let dir_to_allow = match args.call_info.evaluate(registry).await?.args.nth(0) {
|
|
||||||
|
let file_to_trust = match args.call_info.evaluate(registry).await?.args.nth(0) {
|
||||||
Some(Value {
|
Some(Value {
|
||||||
value: UntaggedValue::Primitive(Primitive::String(ref path)),
|
value: UntaggedValue::Primitive(Primitive::String(ref path)),
|
||||||
tag: _,
|
tag: _,
|
||||||
}) => path.clone(),
|
}) => {
|
||||||
_ => std::env::current_dir()?.to_string_lossy().to_string(),
|
let mut dir = path::absolutize(std::env::current_dir()?, path);
|
||||||
|
dir.push(".nu-env");
|
||||||
|
dir
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
let mut dir = std::env::current_dir()?;
|
||||||
|
dir.push(".nu-env");
|
||||||
|
dir
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut env_file_to_allow = PathBuf::from(dir_to_allow.clone());
|
let content = std::fs::read_to_string(&file_to_trust)?;
|
||||||
env_file_to_allow.push(".nu-env");
|
|
||||||
let content = std::fs::read_to_string(env_file_to_allow)?;
|
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
content.hash(&mut hasher);
|
content.hash(&mut hasher);
|
||||||
|
|
||||||
@ -65,9 +72,11 @@ impl WholeStreamCommand for AutoenvTrust {
|
|||||||
let mut allowed: Allowed = toml::from_str(doc.as_str()).unwrap_or_else(|_| Allowed {
|
let mut allowed: Allowed = toml::from_str(doc.as_str()).unwrap_or_else(|_| Allowed {
|
||||||
dirs: IndexMap::new(),
|
dirs: IndexMap::new(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let file_to_allow = file_to_trust.to_string_lossy().to_string();
|
||||||
allowed
|
allowed
|
||||||
.dirs
|
.dirs
|
||||||
.insert(dir_to_allow, hasher.finish().to_string());
|
.insert(file_to_allow, hasher.finish().to_string());
|
||||||
|
|
||||||
fs::write(config_path, toml::to_string(&allowed).unwrap())
|
fs::write(config_path, toml::to_string(&allowed).unwrap())
|
||||||
.expect("Couldn't write to toml file");
|
.expect("Couldn't write to toml file");
|
||||||
|
Loading…
Reference in New Issue
Block a user