Преглед изворни кода

Restore ctime handling with correct pre-epoch behaviour

Thomas Hurst пре 5 година
родитељ
комит
86163ab298
1 измењених фајлова са 12 додато и 2 уклоњено
  1. 12 2
      src/fs/file.rs

+ 12 - 2
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.