mirror of
https://github.com/uutils/diffutils.git
synced 2026-06-10 15:48:59 -07:00
Show current time if fs::metadata errors
This commit is contained in:
+5
-4
@@ -55,11 +55,12 @@ pub fn do_write_line(
|
||||
pub fn get_modification_time(file_path: &str) -> String {
|
||||
use chrono::{DateTime, Local};
|
||||
use std::fs;
|
||||
use std::time::SystemTime;
|
||||
|
||||
let modification_time: SystemTime = fs::metadata(file_path)
|
||||
.and_then(|m| m.modified())
|
||||
.unwrap_or(SystemTime::now());
|
||||
|
||||
let metadata = fs::metadata(file_path).expect("Failed to get metadata");
|
||||
let modification_time = metadata
|
||||
.modified()
|
||||
.expect("Failed to get modification time");
|
||||
let modification_time: DateTime<Local> = modification_time.into();
|
||||
let modification_time: String = modification_time
|
||||
.format("%Y-%m-%d %H:%M:%S%.9f %z")
|
||||
|
||||
Reference in New Issue
Block a user