Fix '/' and '..' not being valid mv targets (#1519)

* Fix '/' and '..' not being valid mv targets

If `/` or `../` is specified as the destination for `mv`, it will fail with an error message saying it's not a valid destination. This fixes it to account for the fact that `Path::file_name` return `None` when the file name evaluates to `/` or `..`. It will only take the slow(er) path if `Path::file_name` returns `None` in its initial check.

Fixes #1291

* Add test
This commit is contained in:
Jon Grythe Stødle
2020-03-24 02:00:48 +01:00
committed by GitHub
parent f030ab3f12
commit 81a48d6d0e
2 changed files with 41 additions and 5 deletions

View File

@ -230,3 +230,23 @@ fn errors_if_source_doesnt_exist() {
assert!(actual.contains("Invalid File or Pattern"));
})
}
#[test]
fn does_not_error_on_relative_parent_path() {
Playground::setup("mv_test_11", |dirs, sandbox| {
sandbox
.mkdir("first")
.with_files(vec![EmptyFile("first/william_hartnell.txt")]);
let original = dirs.test().join("first/william_hartnell.txt");
let expected = dirs.test().join("william_hartnell.txt");
nu!(
cwd: dirs.test().join("first"),
"mv william_hartnell.txt ./.."
);
assert!(!original.exists());
assert!(expected.exists());
})
}