Filestat: make times optional, default to 0 at wasi interface
this is DRY
This commit is contained in:
@@ -92,9 +92,9 @@ pub struct Filestat {
|
|||||||
pub filetype: Filetype,
|
pub filetype: Filetype,
|
||||||
pub nlink: u64,
|
pub nlink: u64,
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
pub atim: std::time::SystemTime,
|
pub atim: Option<std::time::SystemTime>,
|
||||||
pub mtim: std::time::SystemTime,
|
pub mtim: Option<std::time::SystemTime>,
|
||||||
pub ctim: std::time::SystemTime,
|
pub ctim: Option<std::time::SystemTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct FileEntry {
|
pub(crate) struct FileEntry {
|
||||||
@@ -244,19 +244,9 @@ impl WasiFile for cap_std::fs::File {
|
|||||||
filetype: self.get_filetype()?,
|
filetype: self.get_filetype()?,
|
||||||
nlink: meta.nlink(),
|
nlink: meta.nlink(),
|
||||||
size: meta.len(),
|
size: meta.len(),
|
||||||
// XXX handle these features not being available better:
|
atim: meta.accessed().map(|t| Some(t.into_std())).unwrap_or(None),
|
||||||
atim: meta
|
mtim: meta.modified().map(|t| Some(t.into_std())).unwrap_or(None),
|
||||||
.accessed()
|
ctim: meta.created().map(|t| Some(t.into_std())).unwrap_or(None),
|
||||||
.map(|t| t.into_std())
|
|
||||||
.unwrap_or_else(|_| std::time::SystemTime::UNIX_EPOCH),
|
|
||||||
mtim: meta
|
|
||||||
.modified()
|
|
||||||
.map(|t| t.into_std())
|
|
||||||
.unwrap_or_else(|_| std::time::SystemTime::UNIX_EPOCH),
|
|
||||||
ctim: meta
|
|
||||||
.created()
|
|
||||||
.map(|t| t.into_std())
|
|
||||||
.unwrap_or_else(|_| std::time::SystemTime::UNIX_EPOCH),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn set_filestat_size(&self, size: u64) -> Result<(), Error> {
|
fn set_filestat_size(&self, size: u64) -> Result<(), Error> {
|
||||||
|
|||||||
@@ -1034,19 +1034,16 @@ impl From<Filestat> for types::Filestat {
|
|||||||
size: stat.size,
|
size: stat.size,
|
||||||
atim: stat
|
atim: stat
|
||||||
.atim
|
.atim
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.map(|t| t.duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() as u64)
|
||||||
.unwrap()
|
.unwrap_or(0),
|
||||||
.as_nanos() as u64,
|
|
||||||
mtim: stat
|
mtim: stat
|
||||||
.mtim
|
.mtim
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.map(|t| t.duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() as u64)
|
||||||
.unwrap()
|
.unwrap_or(0),
|
||||||
.as_nanos() as u64,
|
|
||||||
ctim: stat
|
ctim: stat
|
||||||
.ctim
|
.ctim
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.map(|t| t.duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() as u64)
|
||||||
.unwrap()
|
.unwrap_or(0),
|
||||||
.as_nanos() as u64,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user