1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Merge pull request #7587 from drinkcat/stat-debug

stat: Print what kind of "weird" mode it is, if it's "weird"
This commit is contained in:
Daniel Hofstetter 2025-03-28 11:03:33 +01:00 committed by GitHub
commit 246da0d0d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 7 deletions

View file

@ -910,9 +910,7 @@ impl Stater {
// raw mode in hex // raw mode in hex
'f' => OutputType::UnsignedHex(meta.mode() as u64), 'f' => OutputType::UnsignedHex(meta.mode() as u64),
// file type // file type
'F' => OutputType::Str( 'F' => OutputType::Str(pretty_filetype(meta.mode() as mode_t, meta.len())),
pretty_filetype(meta.mode() as mode_t, meta.len()).to_owned(),
),
// group ID of owner // group ID of owner
'g' => OutputType::Unsigned(meta.gid() as u64), 'g' => OutputType::Unsigned(meta.gid() as u64),
// group name of owner // group name of owner

View file

@ -880,7 +880,7 @@ where
} }
#[cfg(unix)] #[cfg(unix)]
pub fn pretty_filetype<'a>(mode: mode_t, size: u64) -> &'a str { pub fn pretty_filetype(mode: mode_t, size: u64) -> String {
match mode & S_IFMT { match mode & S_IFMT {
S_IFREG => { S_IFREG => {
if size == 0 { if size == 0 {
@ -896,9 +896,9 @@ pub fn pretty_filetype<'a>(mode: mode_t, size: u64) -> &'a str {
S_IFIFO => "fifo", S_IFIFO => "fifo",
S_IFSOCK => "socket", S_IFSOCK => "socket",
// TODO: Other file types // TODO: Other file types
// See coreutils/gnulib/lib/file-type.c // spell-checker:disable-line _ => return format!("weird file ({:07o})", mode & S_IFMT),
_ => "weird file",
} }
.to_owned()
} }
pub fn pretty_fstype<'a>(fstype: i64) -> Cow<'a, str> { pub fn pretty_fstype<'a>(fstype: i64) -> Cow<'a, str> {
@ -1036,7 +1036,7 @@ mod tests {
assert_eq!("character special file", pretty_filetype(S_IFCHR, 0)); assert_eq!("character special file", pretty_filetype(S_IFCHR, 0));
assert_eq!("regular file", pretty_filetype(S_IFREG, 1)); assert_eq!("regular file", pretty_filetype(S_IFREG, 1));
assert_eq!("regular empty file", pretty_filetype(S_IFREG, 0)); assert_eq!("regular empty file", pretty_filetype(S_IFREG, 0));
assert_eq!("weird file", pretty_filetype(0, 0)); assert_eq!("weird file (0000000)", pretty_filetype(0, 0));
} }
#[test] #[test]