Move path handling to nu-path (#3653)

* fixes #3616
This commit is contained in:
Niklas Jonsson
2021-06-20 01:07:26 +02:00
committed by GitHub
parent b9f1371994
commit a8f6a13239
24 changed files with 645 additions and 465 deletions

View File

@ -1,10 +1,10 @@
use std::path::PathBuf;
use crate::prelude::*;
use nu_engine::filesystem::path::canonicalize;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_path::canonicalize;
use nu_protocol::{CommandAction, ReturnSuccess, Signature, SyntaxShape, UntaggedValue};
use nu_source::Tagged;

View File

@ -2,10 +2,12 @@ use crate::prelude::*;
use nu_engine::{script, WholeStreamCommand};
use nu_errors::ShellError;
use nu_parser::expand_path;
use nu_path::expand_path;
use nu_protocol::{Signature, SyntaxShape};
use nu_source::Tagged;
use std::{borrow::Cow, path::Path};
pub struct Source;
#[derive(Deserialize)]
@ -46,7 +48,7 @@ pub fn source(args: CommandArgs) -> Result<ActionStream, ShellError> {
// Note: this is a special case for setting the context from a command
// In this case, if we don't set it now, we'll lose the scope that this
// variable should be set into.
let contents = std::fs::read_to_string(expand_path(&filename.item).into_owned());
let contents = std::fs::read_to_string(&expand_path(Cow::Borrowed(Path::new(&filename.item))));
match contents {
Ok(contents) => {
let result = script::run_script_standalone(contents, true, &ctx, false);

View File

@ -1,12 +1,11 @@
use super::{operate, PathSubcommandArguments};
use crate::prelude::*;
use nu_engine::filesystem::path::expand_tilde;
use nu_engine::filesystem::path::resolve_dots;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_path::expand_path;
use nu_protocol::{ColumnPath, Signature, SyntaxShape, UntaggedValue, Value};
use nu_source::Span;
use std::path::Path;
use std::{borrow::Cow, path::Path};
pub struct PathExpand;
@ -102,13 +101,7 @@ fn action(path: &Path, tag: Tag, args: &PathExpandArguments) -> Value {
tag.span,
))
} else {
// "best effort" mode, just expand tilde and resolve single/double dots
let path = match expand_tilde(path) {
Some(expanded) => expanded,
None => path.into(),
};
UntaggedValue::filepath(resolve_dots(&path)).into_value(tag)
UntaggedValue::filepath(expand_path(Cow::Borrowed(path))).into_value(tag)
}
}