|
|
@@ -328,7 +328,10 @@ impl<'dir> File<'dir> {
|
|
|
|
|
|
/// This file’s last modified timestamp.
|
|
|
pub fn modified_time(&self) -> Duration {
|
|
|
- self.metadata.modified().unwrap().duration_since(UNIX_EPOCH).unwrap()
|
|
|
+ match self.metadata.modified() {
|
|
|
+ Ok(system_time) => system_time.duration_since(UNIX_EPOCH).unwrap(),
|
|
|
+ Err(_) => Duration::new(0, 0),
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// This file’s last changed timestamp.
|
|
|
@@ -338,12 +341,18 @@ impl<'dir> File<'dir> {
|
|
|
|
|
|
/// This file’s last accessed timestamp.
|
|
|
pub fn accessed_time(&self) -> Duration {
|
|
|
- self.metadata.accessed().unwrap().duration_since(UNIX_EPOCH).unwrap()
|
|
|
+ match self.metadata.accessed() {
|
|
|
+ Ok(system_time) => system_time.duration_since(UNIX_EPOCH).unwrap(),
|
|
|
+ Err(_) => Duration::new(0, 0),
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// This file’s created timestamp.
|
|
|
pub fn created_time(&self) -> Duration {
|
|
|
- self.metadata.created().unwrap().duration_since(UNIX_EPOCH).unwrap()
|
|
|
+ match self.metadata.created() {
|
|
|
+ Ok(system_time) => system_time.duration_since(UNIX_EPOCH).unwrap(),
|
|
|
+ Err(_) => Duration::new(0, 0),
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// This file’s ‘type’.
|
|
|
@@ -460,41 +469,6 @@ impl<'dir> FileTarget<'dir> {
|
|
|
}
|
|
|
|
|
|
|
|
|
-pub enum PlatformMetadata {
|
|
|
- ModifiedTime,
|
|
|
- ChangedTime,
|
|
|
- AccessedTime,
|
|
|
- CreatedTime,
|
|
|
-}
|
|
|
-
|
|
|
-impl PlatformMetadata {
|
|
|
- pub fn check_supported(&self) -> Result<(), Misfire> {
|
|
|
- use std::env::temp_dir;
|
|
|
- let result = match self {
|
|
|
- // Call the functions that return a Result to see if it works
|
|
|
- PlatformMetadata::AccessedTime => metadata(temp_dir()).unwrap().accessed(),
|
|
|
- PlatformMetadata::ModifiedTime => metadata(temp_dir()).unwrap().modified(),
|
|
|
- PlatformMetadata::CreatedTime => metadata(temp_dir()).unwrap().created(),
|
|
|
- // We use the Unix API so we know it’s not available elsewhere
|
|
|
- PlatformMetadata::ChangedTime => {
|
|
|
- if cfg!(target_family = "unix") {
|
|
|
- return Ok(())
|
|
|
- } else {
|
|
|
- return Err(Misfire::Unsupported(
|
|
|
- // for consistency, this error message similar to the one Rust
|
|
|
- // use when created time is not available
|
|
|
- "status modified time is not available on this platform currently".to_string()));
|
|
|
- }
|
|
|
- },
|
|
|
- };
|
|
|
- match result {
|
|
|
- Ok(_) => Ok(()),
|
|
|
- Err(err) => Err(Misfire::Unsupported(err.to_string()))
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
/// More readable aliases for the permission bits exposed by libc.
|
|
|
#[allow(trivial_numeric_casts)]
|
|
|
mod modes {
|