mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +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:
parent
ad3c984afd
commit
5a0dd67003
3 changed files with 40 additions and 31 deletions
|
@ -9,7 +9,7 @@ path = "stat.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
libc = "*"
|
||||
libc = "^0.2"
|
||||
time = "*"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue