diff --git a/src/stat/Cargo.toml b/src/stat/Cargo.toml index f2d6f4c72..da3788528 100644 --- a/src/stat/Cargo.toml +++ b/src/stat/Cargo.toml @@ -9,7 +9,7 @@ path = "stat.rs" [dependencies] getopts = "*" -libc = "*" +libc = "^0.2" time = "*" uucore = { path="../uucore" } diff --git a/src/stat/fsext.rs b/src/stat/fsext.rs index d382f6b95..a169ed084 100644 --- a/src/stat/fsext.rs +++ b/src/stat/fsext.rs @@ -23,7 +23,12 @@ macro_rules! has { pub fn pretty_time(sec: i64, nsec: i64) -> String { let tm = time::at(Timespec::new(sec, nsec as i32)); - time::strftime("%Y-%m-%d %H:%M:%S.%f %z", &tm).unwrap() + let res = time::strftime("%Y-%m-%d %H:%M:%S.%f %z", &tm).unwrap(); + if res.ends_with(" -0000") { + res.replace(" -0000", " +0000") + } else { + res + } } pub fn pretty_filetype<'a>(mode: mode_t, size: u64) -> &'a str { @@ -72,7 +77,7 @@ pub fn pretty_access(mode: mode_t) -> String { } else { '-' }); - result.push(if has!(mode, S_ISUID as u32) { + result.push(if has!(mode, S_ISUID as mode_t) { if has!(mode, S_IXUSR) { 's' } else { @@ -94,7 +99,7 @@ pub fn pretty_access(mode: mode_t) -> String { } else { '-' }); - result.push(if has!(mode, S_ISGID as u32) { + result.push(if has!(mode, S_ISGID as mode_t) { if has!(mode, S_IXGRP) { 's' } else { @@ -116,7 +121,7 @@ pub fn pretty_access(mode: mode_t) -> String { } else { '-' }); - result.push(if has!(mode, S_ISVTX as u32) { + result.push(if has!(mode, S_ISVTX as mode_t) { if has!(mode, S_IXOTH) { 't' } else { @@ -386,19 +391,19 @@ mod test_fsext { assert_eq!("?rw-r-xr-x", pretty_access(0o655)); assert_eq!("brwSr-xr-x", - pretty_access(S_IFBLK | S_ISUID as u32 | 0o655)); + pretty_access(S_IFBLK | S_ISUID as mode_t | 0o655)); assert_eq!("brwsr-xr-x", - pretty_access(S_IFBLK | S_ISUID as u32 | 0o755)); + pretty_access(S_IFBLK | S_ISUID as mode_t | 0o755)); assert_eq!("prw---sr--", - pretty_access(S_IFIFO | S_ISGID as u32 | 0o614)); + pretty_access(S_IFIFO | S_ISGID as mode_t | 0o614)); assert_eq!("prw---Sr--", - pretty_access(S_IFIFO | S_ISGID as u32 | 0o604)); + pretty_access(S_IFIFO | S_ISGID as mode_t | 0o604)); assert_eq!("c---r-xr-t", - pretty_access(S_IFCHR | S_ISVTX as u32 | 0o055)); + pretty_access(S_IFCHR | S_ISVTX as mode_t | 0o055)); assert_eq!("c---r-xr-T", - pretty_access(S_IFCHR | S_ISVTX as u32 | 0o054)); + pretty_access(S_IFCHR | S_ISVTX as mode_t | 0o054)); } #[test] diff --git a/src/stat/stat.rs b/src/stat/stat.rs index 2515c82c3..58152a080 100644 --- a/src/stat/stat.rs +++ b/src/stat/stat.rs @@ -584,7 +584,7 @@ impl Stater { } // file type 'F' => { - arg = pretty_filetype(meta.mode(), meta.len()).to_owned(); + arg = pretty_filetype(meta.mode() as mode_t, meta.len()).to_owned(); otype = OutputType::Str; } // group ID of owner @@ -622,13 +622,13 @@ impl Stater { // quoted file name with dereference if symbolic link 'N' => { if ftype.is_symlink() { - arg = format!("'{}' -> '{}'", + arg = format!("`{}' -> `{}'", file, fs::read_link(file) .expect("Invalid symlink") .to_string_lossy()); } else { - arg = format!("'{}'", file); + arg = format!("`{}'", file); } otype = OutputType::Str; } @@ -667,28 +667,32 @@ impl Stater { // time of file birth, human-readable; - if unknown 'w' => { - arg = if let Ok(elapsed) = meta.created() - .map(|t| { - t.elapsed().unwrap() - }) { - pretty_time(elapsed.as_secs() as i64, - elapsed.subsec_nanos() as i64) - } else { - "-".to_owned() - }; + // Unstable. Commented + //arg = if let Ok(elapsed) = meta.created() + //.map(|t| { + //t.elapsed().unwrap() + //}) { + //pretty_time(elapsed.as_secs() as i64, + //elapsed.subsec_nanos() as i64) + //} else { + //"-".to_owned() + //}; + arg = "-".to_owned(); otype = OutputType::Str; } // time of file birth, seconds since Epoch; 0 if unknown 'W' => { - arg = if let Ok(elapsed) = meta.created() - .map(|t| { - t.elapsed().unwrap() - }) { - format!("{}", elapsed.as_secs()) - } else { - "0".to_owned() - }; + // Unstable. Commented + //arg = if let Ok(elapsed) = meta.created() + //.map(|t| { + //t.elapsed().unwrap() + //}) { + //format!("{}", elapsed.as_secs()) + //} else { + //"0".to_owned() + //}; + arg = "0".to_owned(); otype = OutputType::Integer; }