Cleanup, stop tracking overwritten values as nu takes care of it
This commit is contained in:
parent
acd3215b36
commit
a173817889
5
crates/nu-cli/src/env/TODO.org
vendored
5
crates/nu-cli/src/env/TODO.org
vendored
|
@ -20,6 +20,11 @@ returning =None=, which completely skips running the code for dealing with direc
|
|||
- This holds even if the old value was set by a .nu in a parent directory. The overwritten value is restored when you leave the directory.
|
||||
** Security
|
||||
https://github.com/nushell/nushell/issues/1965
|
||||
- Add trust subcommand
|
||||
- The trust subcommand should hash the current directory path and the content of its .nu-env.
|
||||
- If the directory path changes or the content of the .nu-env changes, show a warning.
|
||||
- Add distrust subcommand
|
||||
- Add command to clear allowed .nu-envs in a directory.
|
||||
** Nice errors
|
||||
** Potential issues
|
||||
- Functionality to re-add overwritten variables is currently untested.
|
||||
|
|
|
@ -67,19 +67,14 @@ impl DirectorySpecificEnvironment {
|
|||
.for_each(|(dir_env_key, dir_env_val)| {
|
||||
let dir_env_val: EnvVal = dir_env_val.as_str().unwrap().into();
|
||||
|
||||
//If we are about to overwrite any environment variables, we save them first so they can be restored later.
|
||||
if std::env::var_os(dir_env_key).is_some()
|
||||
&& !vars_to_add.contains_key(dir_env_key)
|
||||
{
|
||||
//This condition is to make sure variables in parent directories don't overwrite variables set by subdirectories.
|
||||
//This condition is to make sure variables in parent directories don't overwrite variables set by subdirectories.
|
||||
if !vars_to_add.contains_key(dir_env_key) {
|
||||
vars_to_add.insert(dir_env_key.clone(), dir_env_val);
|
||||
} else {
|
||||
//Otherwise, we just track that we added it here
|
||||
|
||||
self.added_env_vars
|
||||
.entry(wdir.to_path_buf())
|
||||
.or_insert(IndexSet::new())
|
||||
.insert(dir_env_key.clone());
|
||||
vars_to_add.insert(dir_env_key.clone(), dir_env_val);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
11
crates/nu-cli/src/env/environment.rs
vendored
11
crates/nu-cli/src/env/environment.rs
vendored
|
@ -1,10 +1,9 @@
|
|||
use crate::data::config::Conf;
|
||||
use std::io::Write;
|
||||
use crate::env::directory_specific_environment::*;
|
||||
use indexmap::{indexmap, IndexSet};
|
||||
use nu_protocol::{UntaggedValue, Value};
|
||||
use std::ffi::OsString;
|
||||
use std::{fs::OpenOptions, fmt::Debug};
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub trait Env: Debug + Send {
|
||||
fn env(&self) -> Option<Value>;
|
||||
|
@ -64,15 +63,7 @@ impl Environment {
|
|||
self.remove_env(&k);
|
||||
});
|
||||
|
||||
self.direnv
|
||||
.overwritten_values_to_restore()?
|
||||
.iter()
|
||||
.for_each(|(k, v)| {
|
||||
self.add_env(&k, &v.to_string_lossy(), true);
|
||||
});
|
||||
|
||||
self.direnv.env_vars_to_add()?.iter().for_each(|(k, v)| {
|
||||
// std::env::set_var(k, v);
|
||||
self.add_env(&k, &v.to_string_lossy(), true);
|
||||
});
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue
Block a user