Restore ctime handling with correct pre-epoch behaviour

This commit is contained in:
Thomas Hurst 2020-05-18 23:06:27 +00:00
parent d2d2e7325f
commit 86163ab298

View File

@ -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 files 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 files last accessed timestamp.