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

stat: make ci happy

1. force ci to use libc@0.2
2. dont use unstable api Metadata::created
3. change quote style
4. pass metadata.mode() as mode_t
This commit is contained in:
Knight 2016-06-05 11:49:49 +08:00
parent ad3c984afd
commit 5a0dd67003
3 changed files with 40 additions and 31 deletions

View file

@ -9,7 +9,7 @@ path = "stat.rs"
[dependencies] [dependencies]
getopts = "*" getopts = "*"
libc = "*" libc = "^0.2"
time = "*" time = "*"
uucore = { path="../uucore" } uucore = { path="../uucore" }

View file

@ -23,7 +23,12 @@ macro_rules! has {
pub fn pretty_time(sec: i64, nsec: i64) -> String { pub fn pretty_time(sec: i64, nsec: i64) -> String {
let tm = time::at(Timespec::new(sec, nsec as i32)); 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 { 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 { } 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) { if has!(mode, S_IXUSR) {
's' 's'
} else { } else {
@ -94,7 +99,7 @@ pub fn pretty_access(mode: mode_t) -> String {
} else { } 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) { if has!(mode, S_IXGRP) {
's' 's'
} else { } else {
@ -116,7 +121,7 @@ pub fn pretty_access(mode: mode_t) -> String {
} else { } 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) { if has!(mode, S_IXOTH) {
't' 't'
} else { } else {
@ -386,19 +391,19 @@ mod test_fsext {
assert_eq!("?rw-r-xr-x", pretty_access(0o655)); assert_eq!("?rw-r-xr-x", pretty_access(0o655));
assert_eq!("brwSr-xr-x", 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", 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--", 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--", 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", 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", 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] #[test]

View file

@ -584,7 +584,7 @@ impl Stater {
} }
// file type // file type
'F' => { '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; otype = OutputType::Str;
} }
// group ID of owner // group ID of owner
@ -622,13 +622,13 @@ impl Stater {
// quoted file name with dereference if symbolic link // quoted file name with dereference if symbolic link
'N' => { 'N' => {
if ftype.is_symlink() { if ftype.is_symlink() {
arg = format!("'{}' -> '{}'", arg = format!("`{}' -> `{}'",
file, file,
fs::read_link(file) fs::read_link(file)
.expect("Invalid symlink") .expect("Invalid symlink")
.to_string_lossy()); .to_string_lossy());
} else { } else {
arg = format!("'{}'", file); arg = format!("`{}'", file);
} }
otype = OutputType::Str; otype = OutputType::Str;
} }
@ -667,28 +667,32 @@ impl Stater {
// time of file birth, human-readable; - if unknown // time of file birth, human-readable; - if unknown
'w' => { 'w' => {
arg = if let Ok(elapsed) = meta.created() // Unstable. Commented
.map(|t| { //arg = if let Ok(elapsed) = meta.created()
t.elapsed().unwrap() //.map(|t| {
}) { //t.elapsed().unwrap()
pretty_time(elapsed.as_secs() as i64, //}) {
elapsed.subsec_nanos() as i64) //pretty_time(elapsed.as_secs() as i64,
} else { //elapsed.subsec_nanos() as i64)
"-".to_owned() //} else {
}; //"-".to_owned()
//};
arg = "-".to_owned();
otype = OutputType::Str; otype = OutputType::Str;
} }
// time of file birth, seconds since Epoch; 0 if unknown // time of file birth, seconds since Epoch; 0 if unknown
'W' => { 'W' => {
arg = if let Ok(elapsed) = meta.created() // Unstable. Commented
.map(|t| { //arg = if let Ok(elapsed) = meta.created()
t.elapsed().unwrap() //.map(|t| {
}) { //t.elapsed().unwrap()
format!("{}", elapsed.as_secs()) //}) {
} else { //format!("{}", elapsed.as_secs())
"0".to_owned() //} else {
}; //"0".to_owned()
//};
arg = "0".to_owned();
otype = OutputType::Integer; otype = OutputType::Integer;
} }