summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hurst <tom@hur.st>2020-05-18 23:06:27 +0000
committerThomas Hurst <tom@hur.st>2020-05-18 23:21:56 +0000
commit86163ab29890c427c23fc79b26e0fca65c28b933 (patch)
treee01a46790349bca17cdf6c55ef8ecfc192e117a7
parentd2d2e7325f1fe03d3407a71cd79d9ffa52c8f892 (diff)
Restore ctime handling with correct pre-epoch behaviour
-rw-r--r--src/fs/file.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/fs/file.rs b/src/fs/file.rs
index ee33de1..35b2940 100644
--- a/src/fs/file.rs
+++ b/src/fs/file.rs
@@ -4,7 +4,7 @@ use std::io::Error as IOError;
use std::io::Result as IOResult;
use std::os::unix::fs::{MetadataExt, PermissionsExt, FileTypeExt};
use std::path::{Path, PathBuf};
-use std::time::{SystemTime, UNIX_EPOCH};
+use std::time::{Duration, SystemTime, UNIX_EPOCH};
use log::{debug, error};
@@ -333,7 +333,17 @@ impl<'dir> File<'dir> {
/// This file’s last changed timestamp.
pub fn changed_time(&self) -> SystemTime {
- self.metadata.modified().unwrap_or(UNIX_EPOCH)
+ let (mut sec, mut nsec) = (self.metadata.ctime(), self.metadata.ctime_nsec());
+
+ if sec < 0 { // yeah right
+ if nsec > 0 {
+ sec += 1;
+ nsec = nsec - 1_000_000_000;
+ }
+ UNIX_EPOCH - Duration::new(sec.abs() as u64, nsec.abs() as u32)
+ } else {
+ UNIX_EPOCH + Duration::new(sec as u64, nsec as u32)
+ }
}
/// This file’s last accessed timestamp.