Show current time if fs::metadata errors

This commit is contained in:
Tanmay Patil
2024-04-04 20:01:11 +05:30
parent 61fb0657c1
commit 72da7fca40
+5 -4
View File
@@ -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")