forked from extern/nushell
Small fixes and refactors to paths & source command (#3998)
* Expand path when converting value -> PathBuf Also includes Tagged<PathBuf>. Fixes #3605 * Expand path for PATH env. variable Fixes #1834 * Remove leftover Cows after nu-path refactor There were some unnecessary Cow conversions leftover from the old nu-path implementation. * Use canonicalize in source command; Improve errors Previously, `source` used `expand_path()` which does not follow symlinks. As a follow up, I improved the source error messages so they now tell why the source file could not be canonicalized or read into string.
This commit is contained in:
@ -10,6 +10,7 @@ use crate::{env::basic_host::BasicHost, Host};
|
||||
|
||||
use nu_data::config::{self, Conf, NuConfig};
|
||||
use nu_errors::ShellError;
|
||||
use nu_path::expand_path;
|
||||
use nu_protocol::{hir, ConfigPath, VariableRegistry};
|
||||
use nu_source::Spanned;
|
||||
use nu_source::{Span, Tag};
|
||||
@ -157,7 +158,7 @@ impl EvaluationContext {
|
||||
|
||||
for (var, val) in env_vars {
|
||||
if var == NATIVE_PATH_ENV_VAR {
|
||||
std::env::set_var(var, val);
|
||||
std::env::set_var(var, expand_path(val));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ use std::path::PathBuf;
|
||||
use bigdecimal::{BigDecimal, ToPrimitive};
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use nu_errors::ShellError;
|
||||
use nu_path::expand_path;
|
||||
use nu_protocol::{
|
||||
hir::CapturedBlock, ColumnPath, Dictionary, Primitive, Range, SpannedTypeName, UntaggedValue,
|
||||
Value,
|
||||
@ -239,11 +240,11 @@ impl FromValue for PathBuf {
|
||||
Value {
|
||||
value: UntaggedValue::Primitive(Primitive::String(s)),
|
||||
..
|
||||
} => Ok(PathBuf::from(s)),
|
||||
} => Ok(expand_path(s)),
|
||||
Value {
|
||||
value: UntaggedValue::Primitive(Primitive::FilePath(p)),
|
||||
..
|
||||
} => Ok(p.clone()),
|
||||
} => Ok(expand_path(p)),
|
||||
Value {
|
||||
value: UntaggedValue::Row(_),
|
||||
..
|
||||
@ -265,11 +266,11 @@ impl FromValue for Tagged<PathBuf> {
|
||||
Value {
|
||||
value: UntaggedValue::Primitive(Primitive::String(s)),
|
||||
tag,
|
||||
} => Ok(PathBuf::from(s).tagged(tag)),
|
||||
} => Ok(expand_path(s).tagged(tag)),
|
||||
Value {
|
||||
value: UntaggedValue::Primitive(Primitive::FilePath(p)),
|
||||
tag,
|
||||
} => Ok(p.clone().tagged(tag)),
|
||||
} => Ok(expand_path(p).tagged(tag)),
|
||||
Value {
|
||||
value: UntaggedValue::Row(_),
|
||||
..
|
||||
|
Reference in New Issue
Block a user