forked from extern/nushell
Fixes how environment is cloned inside tight loops (#678)
* Improve cd IO error * Fix environment cloning in loops * Remove debug print * Fmt
This commit is contained in:
parent
14cd798f00
commit
d0c280f6cc
@ -34,11 +34,15 @@ impl Command for Cd {
|
|||||||
let (path, span) = match path_val {
|
let (path, span) = match path_val {
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
let path = v.as_path()?;
|
let path = v.as_path()?;
|
||||||
if !path.exists() {
|
let path = match nu_path::canonicalize_with(path, &cwd) {
|
||||||
return Err(ShellError::DirectoryNotFound(v.span()?));
|
Ok(p) => p,
|
||||||
|
Err(e) => {
|
||||||
|
return Err(ShellError::DirectoryNotFoundHelp(
|
||||||
|
v.span()?,
|
||||||
|
format!("IO Error: {:?}", e),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
};
|
||||||
let path = nu_path::canonicalize_with(path, &cwd)?;
|
|
||||||
(path.to_string_lossy().to_string(), v.span()?)
|
(path.to_string_lossy().to_string(), v.span()?)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -82,8 +82,7 @@ impl Command for Each {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(move |(idx, x)| {
|
.map(move |(idx, x)| {
|
||||||
stack.env_vars = orig_env_vars.clone();
|
stack.with_env(&orig_env_vars, &orig_env_hidden);
|
||||||
stack.env_hidden = orig_env_hidden.clone();
|
|
||||||
|
|
||||||
if let Some(var) = block.signature.get_positional(0) {
|
if let Some(var) = block.signature.get_positional(0) {
|
||||||
if let Some(var_id) = &var.var_id {
|
if let Some(var_id) = &var.var_id {
|
||||||
|
@ -47,11 +47,12 @@ impl Stack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_env(&mut self, env_vars: &[HashMap<String, Value>], env_hidden: &HashSet<String>) {
|
pub fn with_env(&mut self, env_vars: &[HashMap<String, Value>], env_hidden: &HashSet<String>) {
|
||||||
if env_vars.iter().any(|scope| !scope.is_empty()) {
|
// Do not clone the environment if it hasn't changed
|
||||||
|
if self.env_vars.iter().any(|scope| !scope.is_empty()) {
|
||||||
self.env_vars = env_vars.to_owned();
|
self.env_vars = env_vars.to_owned();
|
||||||
}
|
}
|
||||||
|
|
||||||
if !env_hidden.is_empty() {
|
if !self.env_hidden.is_empty() {
|
||||||
self.env_hidden = env_hidden.clone();
|
self.env_hidden = env_hidden.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,10 +189,14 @@ pub enum ShellError {
|
|||||||
#[diagnostic(code(nu::shell::directory_not_found), url(docsrs))]
|
#[diagnostic(code(nu::shell::directory_not_found), url(docsrs))]
|
||||||
DirectoryNotFound(#[label("directory not found")] Span),
|
DirectoryNotFound(#[label("directory not found")] Span),
|
||||||
|
|
||||||
#[error("File not found")]
|
#[error("Directory not found")]
|
||||||
#[diagnostic(code(nu::shell::file_not_found), url(docsrs))]
|
#[diagnostic(code(nu::shell::directory_not_found_custom), url(docsrs))]
|
||||||
DirectoryNotFoundCustom(String, #[label("{0}")] Span),
|
DirectoryNotFoundCustom(String, #[label("{0}")] Span),
|
||||||
|
|
||||||
|
#[error("Directory not found")]
|
||||||
|
#[diagnostic(code(nu::shell::directory_not_found_help), url(docsrs), help("{1}"))]
|
||||||
|
DirectoryNotFoundHelp(#[label("directory not found")] Span, String),
|
||||||
|
|
||||||
#[error("Move not possible")]
|
#[error("Move not possible")]
|
||||||
#[diagnostic(code(nu::shell::move_not_possible), url(docsrs))]
|
#[diagnostic(code(nu::shell::move_not_possible), url(docsrs))]
|
||||||
MoveNotPossible {
|
MoveNotPossible {
|
||||||
|
Loading…
Reference in New Issue
Block a user