mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
uucore/perms: correct some error messages
- prevent duplicate errors from both us and `walkdir` by instructing `walkdir' to skip directories we failed to read metadata for. - don't directly display `walkdir`'s errors, but format them ourselves to match gnu's format
This commit is contained in:
parent
a517671d55
commit
18fc4076cf
2 changed files with 80 additions and 29 deletions
|
@ -230,7 +230,7 @@ fn test_big_h() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(not(target_vendor = "apple"))]
|
||||
fn basic_succeeds() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let one_group = nix::unistd::getgroups().unwrap();
|
||||
|
@ -251,3 +251,40 @@ fn test_no_change() {
|
|||
at.touch("file");
|
||||
ucmd.arg("").arg(at.plus("file")).succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_vendor = "apple"))]
|
||||
fn test_permission_denied() {
|
||||
use std::os::unix::prelude::PermissionsExt;
|
||||
|
||||
if let Some(group) = nix::unistd::getgroups().unwrap().first() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("dir");
|
||||
at.touch("dir/file");
|
||||
std::fs::set_permissions(at.plus("dir"), PermissionsExt::from_mode(0o0000)).unwrap();
|
||||
ucmd.arg("-R")
|
||||
.arg(group.as_raw().to_string())
|
||||
.arg("dir")
|
||||
.fails()
|
||||
.stderr_only("chgrp: cannot access 'dir': Permission denied");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_vendor = "apple"))]
|
||||
fn test_subdir_permission_denied() {
|
||||
use std::os::unix::prelude::PermissionsExt;
|
||||
|
||||
if let Some(group) = nix::unistd::getgroups().unwrap().first() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("dir");
|
||||
at.mkdir("dir/subdir");
|
||||
at.touch("dir/subdir/file");
|
||||
std::fs::set_permissions(at.plus("dir/subdir"), PermissionsExt::from_mode(0o0000)).unwrap();
|
||||
ucmd.arg("-R")
|
||||
.arg(group.as_raw().to_string())
|
||||
.arg("dir")
|
||||
.fails()
|
||||
.stderr_only("chgrp: cannot access 'dir/subdir': Permission denied");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue