Skip to content

Commit 3d0c59a

Browse files
committed
stat: Print what kind of "weird" mode it is, if it's "weird"
Maybe useful to (partially) understand what is going on in #7583.
1 parent f03cbf2 commit 3d0c59a

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/uu/stat/src/stat.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,9 +910,7 @@ impl Stater {
910910
// raw mode in hex
911911
'f' => OutputType::UnsignedHex(meta.mode() as u64),
912912
// file type
913-
'F' => OutputType::Str(
914-
pretty_filetype(meta.mode() as mode_t, meta.len()).to_owned(),
915-
),
913+
'F' => OutputType::Str(pretty_filetype(meta.mode() as mode_t, meta.len())),
916914
// group ID of owner
917915
'g' => OutputType::Unsigned(meta.gid() as u64),
918916
// group name of owner

src/uucore/src/lib/features/fsext.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ where
880880
}
881881

882882
#[cfg(unix)]
883-
pub fn pretty_filetype<'a>(mode: mode_t, size: u64) -> &'a str {
883+
pub fn pretty_filetype(mode: mode_t, size: u64) -> String {
884884
match mode & S_IFMT {
885885
S_IFREG => {
886886
if size == 0 {
@@ -896,9 +896,9 @@ pub fn pretty_filetype<'a>(mode: mode_t, size: u64) -> &'a str {
896896
S_IFIFO => "fifo",
897897
S_IFSOCK => "socket",
898898
// TODO: Other file types
899-
// See coreutils/gnulib/lib/file-type.c // spell-checker:disable-line
900-
_ => "weird file",
899+
_ => return format!("weird file ({:07o})", mode & S_IFMT),
901900
}
901+
.to_owned()
902902
}
903903

904904
pub fn pretty_fstype<'a>(fstype: i64) -> Cow<'a, str> {
@@ -1036,7 +1036,7 @@ mod tests {
10361036
assert_eq!("character special file", pretty_filetype(S_IFCHR, 0));
10371037
assert_eq!("regular file", pretty_filetype(S_IFREG, 1));
10381038
assert_eq!("regular empty file", pretty_filetype(S_IFREG, 0));
1039-
assert_eq!("weird file", pretty_filetype(0, 0));
1039+
assert_eq!("weird file (0000000)", pretty_filetype(0, 0));
10401040
}
10411041

10421042
#[test]

0 commit comments

Comments
 (0)