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:
Jakub Žádník
2021-09-12 02:36:14 +03:00
committed by GitHub
parent 0fa0c25fb3
commit cc5c4d38bb
6 changed files with 55 additions and 36 deletions

View File

@ -1,4 +1,3 @@
use std::borrow::Cow;
use std::path::{is_separator, Path, PathBuf};
use super::matchers::Matcher;
@ -27,7 +26,7 @@ impl PathCompleter {
(base, rest)
};
let base_dir = nu_path::expand_path(Cow::Borrowed(Path::new(&base_dir_name)));
let base_dir = nu_path::expand_path(&base_dir_name);
// This check is here as base_dir.read_dir() with base_dir == "" will open the current dir
// which we don't want in this case (if we did, base_dir would already be ".")
if base_dir == Path::new("") {