From 3d0c59ae97d6b1eab084bc1ece6ee7fd563a3830 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Wed, 26 Mar 2025 20:19:08 +0100 Subject: [PATCH] stat: Print what kind of "weird" mode it is, if it's "weird" Maybe useful to (partially) understand what is going on in #7583. --- src/uu/stat/src/stat.rs | 4 +--- src/uucore/src/lib/features/fsext.rs | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 706e8157d..640d0af41 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -910,9 +910,7 @@ impl Stater { // raw mode in hex 'f' => OutputType::UnsignedHex(meta.mode() as u64), // file type - 'F' => OutputType::Str( - pretty_filetype(meta.mode() as mode_t, meta.len()).to_owned(), - ), + 'F' => OutputType::Str(pretty_filetype(meta.mode() as mode_t, meta.len())), // group ID of owner 'g' => OutputType::Unsigned(meta.gid() as u64), // group name of owner diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 9f38c1815..c32a31320 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -880,7 +880,7 @@ where } #[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 { S_IFREG => { if size == 0 { @@ -896,9 +896,9 @@ pub fn pretty_filetype<'a>(mode: mode_t, size: u64) -> &'a str { S_IFIFO => "fifo", S_IFSOCK => "socket", // TODO: Other file types - // See coreutils/gnulib/lib/file-type.c // spell-checker:disable-line - _ => "weird file", + _ => return format!("weird file ({:07o})", mode & S_IFMT), } + .to_owned() } 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!("regular file", pretty_filetype(S_IFREG, 1)); 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]