From 1b83248558f45ee7ee35a254ffcb9dc3bc5503eb Mon Sep 17 00:00:00 2001 From: Sam Hedin Date: Mon, 22 Jun 2020 13:48:29 +0200 Subject: [PATCH] Fix path --- crates/nu-cli/src/commands/autoenv_trust.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/nu-cli/src/commands/autoenv_trust.rs b/crates/nu-cli/src/commands/autoenv_trust.rs index 762ec9e754..770b2a6131 100644 --- a/crates/nu-cli/src/commands/autoenv_trust.rs +++ b/crates/nu-cli/src/commands/autoenv_trust.rs @@ -1,6 +1,6 @@ -use super::autoenv::Allowed; +use super::{autoenv::Allowed, cd::CdArgs}; use crate::commands::WholeStreamCommand; -use crate::prelude::*; +use crate::{path, prelude::*}; use nu_errors::ShellError; use nu_protocol::SyntaxShape; use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value}; @@ -29,16 +29,19 @@ impl WholeStreamCommand for AutoenvTrust { registry: &CommandRegistry, ) -> Result { let tag = args.call_info.name_tag.clone(); + let dir_to_allow = match args.call_info.evaluate(registry).await?.args.nth(0) { Some(Value { value: UntaggedValue::Primitive(Primitive::String(ref path)), tag: _, - }) => path.clone(), + }) => path::absolutize(std::env::current_dir()?, path) + .to_string_lossy() + .to_string(), _ => std::env::current_dir()?.to_string_lossy().to_string(), }; - let mut env_file_to_allow = PathBuf::from(dir_to_allow.clone()); 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);