Skip to content

Commit 72da7fc

Browse files
Show current time if fs::metadata errors
1 parent 61fb065 commit 72da7fc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/utils.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ pub fn do_write_line(
5555
pub fn get_modification_time(file_path: &str) -> String {
5656
use chrono::{DateTime, Local};
5757
use std::fs;
58+
use std::time::SystemTime;
59+
60+
let modification_time: SystemTime = fs::metadata(file_path)
61+
.and_then(|m| m.modified())
62+
.unwrap_or(SystemTime::now());
5863

59-
let metadata = fs::metadata(file_path).expect("Failed to get metadata");
60-
let modification_time = metadata
61-
.modified()
62-
.expect("Failed to get modification time");
6364
let modification_time: DateTime<Local> = modification_time.into();
6465
let modification_time: String = modification_time
6566
.format("%Y-%m-%d %H:%M:%S%.9f %z")

0 commit comments

Comments
 (0)