mirror of
https://github.com/uutils/coreutils
synced 2025-01-18 16:14:13 +00:00
Merge pull request #2273 from ycd/mv-perm-error
mv: log proper error message when permission error occurs
This commit is contained in:
commit
cdd74afa3f
2 changed files with 29 additions and 4 deletions
|
@ -295,7 +295,7 @@ fn exec(files: &[PathBuf], b: Behavior) -> i32 {
|
|||
"cannot move ‘{}’ to ‘{}’: {}",
|
||||
source.display(),
|
||||
target.display(),
|
||||
e
|
||||
e.to_string()
|
||||
);
|
||||
1
|
||||
}
|
||||
|
@ -358,14 +358,15 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> i3
|
|||
|
||||
if let Err(e) = rename(sourcepath, &targetpath, b) {
|
||||
show_error!(
|
||||
"mv: cannot move ‘{}’ to ‘{}’: {}",
|
||||
"cannot move ‘{}’ to ‘{}’: {}",
|
||||
sourcepath.display(),
|
||||
targetpath.display(),
|
||||
e
|
||||
e.to_string()
|
||||
);
|
||||
all_successful = false;
|
||||
}
|
||||
}
|
||||
|
||||
if all_successful {
|
||||
0
|
||||
} else {
|
||||
|
@ -452,7 +453,13 @@ fn rename_with_fallback(from: &Path, to: &Path) -> io::Result<()> {
|
|||
..DirCopyOptions::new()
|
||||
};
|
||||
if let Err(err) = move_dir(from, to, &options) {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, format!("{:?}", err)));
|
||||
return match err.kind {
|
||||
fs_extra::error::ErrorKind::PermissionDenied => Err(io::Error::new(
|
||||
io::ErrorKind::PermissionDenied,
|
||||
"Permission denied",
|
||||
)),
|
||||
_ => Err(io::Error::new(io::ErrorKind::Other, format!("{:?}", err))),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
fs::copy(from, to).and_then(|_| fs::remove_file(from))?;
|
||||
|
|
|
@ -587,6 +587,24 @@ fn test_mv_verbose() {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_permission_error() {
|
||||
let scene = TestScenario::new("mkdir");
|
||||
let folder1 = "bar";
|
||||
let folder2 = "foo";
|
||||
let folder_to_move = "bar/foo";
|
||||
scene.ucmd().arg("-m444").arg(folder1).succeeds();
|
||||
scene.ucmd().arg("-m777").arg(folder2).succeeds();
|
||||
|
||||
scene
|
||||
.cmd_keepenv(util_name!())
|
||||
.arg(folder2)
|
||||
.arg(folder_to_move)
|
||||
.run()
|
||||
.stderr_str()
|
||||
.ends_with("Permission denied");
|
||||
}
|
||||
|
||||
// Todo:
|
||||
|
||||
// $ at.touch a b
|
||||
|
|
Loading…
Reference in a new issue