stat: fix unstable library

This commit is contained in:
Knight 2016-06-17 18:30:08 +08:00
parent 13d06ff800
commit 2758455d73
2 changed files with 33 additions and 18 deletions

View file

@ -14,6 +14,37 @@ pub use self::libc::{S_IFMT, S_IFDIR, S_IFCHR, S_IFBLK, S_IFREG, S_IFIFO, S_IFLN
S_ISVTX, S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP, S_IXGRP, S_IROTH, S_IWOTH, S_IXOTH, mode_t,
c_int, strerror};
pub trait BirthTime {
fn pretty_birth(&self) -> String;
fn birth(&self) -> String;
}
use std::fs::Metadata;
impl BirthTime for Metadata {
#[cfg(feature = "nightly")]
fn pretty_birth(&self) -> String {
self.created()
.map(|t| t.elapsed().unwrap())
.map(|e| pretty_time(e.as_secs() as i64, e.subsec_nanos() as i64))
.unwrap_or("-".to_owned())
}
#[cfg(not(feature = "nightly"))]
fn pretty_birth(&self) -> String {
"-".to_owned()
}
#[cfg(feature = "nightly")]
fn birth(&self) -> String {
self.created()
.map(|t| t.elapsed().unwrap())
.map(|e| format!("{}", e.as_secs()))
.unwrap_or("0".to_owned())
}
#[cfg(not(feature = "nightly"))]
fn birth(&self) -> String {
"0".to_owned()
}
}
#[macro_export]
macro_rules! has {
($mode:expr, $perm:expr) => (

View file

@ -689,29 +689,13 @@ impl Stater {
// time of file birth, human-readable; - if unknown
'w' => {
arg = if cfg!(feature = "nightly") {
// Unstable
meta.created()
.map(|t| t.elapsed().unwrap())
.map(|e| pretty_time(e.as_secs() as i64, e.subsec_nanos() as i64))
.unwrap_or("-".to_owned())
} else {
"-".to_owned()
};
arg = meta.pretty_birth();
otype = OutputType::Str;
}
// time of file birth, seconds since Epoch; 0 if unknown
'W' => {
arg = if cfg!(feature = "nightly") {
// Unstable
meta.created()
.map(|t| t.elapsed().unwrap())
.map(|e| format!("{}", e.as_secs()))
.unwrap_or("0".to_owned())
} else {
"0".to_owned()
};
arg = meta.birth();
otype = OutputType::Integer;
}