mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
fix: log error messages properly on permission errors
This commit is contained in:
parent
da085eca98
commit
991fcc548c
2 changed files with 43 additions and 8 deletions
|
@ -291,12 +291,22 @@ fn exec(files: &[PathBuf], b: Behavior) -> i32 {
|
||||||
|
|
||||||
return match rename(source, target, &b) {
|
return match rename(source, target, &b) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
let error_as_str = e.to_string();
|
||||||
|
let is_perm_denied = error_as_str.contains("Permission denied");
|
||||||
|
match e.kind() {
|
||||||
|
_ => {
|
||||||
show_error!(
|
show_error!(
|
||||||
"cannot move ‘{}’ to ‘{}’: {}",
|
"cannot move ‘{}’ to ‘{}’: {}",
|
||||||
source.display(),
|
source.display(),
|
||||||
target.display(),
|
target.display(),
|
||||||
e
|
if is_perm_denied {
|
||||||
|
"Permission denied".to_string()
|
||||||
|
} else {
|
||||||
|
e.to_string()
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
_ => 0,
|
_ => 0,
|
||||||
|
@ -357,15 +367,22 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> i3
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = rename(sourcepath, &targetpath, b) {
|
if let Err(e) = rename(sourcepath, &targetpath, b) {
|
||||||
|
let error_as_str = e.to_string();
|
||||||
|
let is_perm_denied = error_as_str.contains("Permission denied");
|
||||||
show_error!(
|
show_error!(
|
||||||
"mv: cannot move ‘{}’ to ‘{}’: {}",
|
"cannot move ‘{}’ to ‘{}’: {}",
|
||||||
sourcepath.display(),
|
sourcepath.display(),
|
||||||
targetpath.display(),
|
targetpath.display(),
|
||||||
e
|
if is_perm_denied {
|
||||||
|
"Permission denied".to_string()
|
||||||
|
} else {
|
||||||
|
e.to_string()
|
||||||
|
}
|
||||||
);
|
);
|
||||||
all_successful = false;
|
all_successful = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if all_successful {
|
if all_successful {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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:
|
// Todo:
|
||||||
|
|
||||||
// $ at.touch a b
|
// $ at.touch a b
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue