forked from extern/nushell
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:
committed by
GitHub
parent
f030ab3f12
commit
81a48d6d0e
@ -631,11 +631,27 @@ impl Shell for FilesystemShell {
|
||||
match destination.file_name() {
|
||||
Some(name) => PathBuf::from(name),
|
||||
None => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Rename aborted. Not a valid destination",
|
||||
"not a valid destination",
|
||||
dst.tag,
|
||||
))
|
||||
let name_maybe =
|
||||
destination.components().next_back().and_then(
|
||||
|component| match component {
|
||||
Component::RootDir => Some(PathBuf::from("/")),
|
||||
Component::ParentDir => destination
|
||||
.parent()
|
||||
.and_then(|parent| parent.file_name())
|
||||
.map(PathBuf::from),
|
||||
_ => None,
|
||||
},
|
||||
);
|
||||
|
||||
if let Some(name) = name_maybe {
|
||||
name
|
||||
} else {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Rename aborted. Not a valid destination",
|
||||
"not a valid destination",
|
||||
dst.tag,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user