use non-panicky timestamp_opt where appropriate

by either printing the original, out-of-range timestamp as-is, or
bailing with a proper error message instead of panicking.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler
2020-09-11 14:34:36 +02:00
committed by Dietmar Maurer
parent 151acf5d96
commit 833eca6d2f
3 changed files with 26 additions and 8 deletions

View File

@ -6,7 +6,7 @@ use super::chunk_store::*;
use super::{IndexFile, ChunkReadInfo};
use crate::tools::{self, epoch_now_u64};
use chrono::{Local, TimeZone};
use chrono::{Local, LocalResult, TimeZone};
use std::fs::File;
use std::io::Write;
use std::os::unix::io::AsRawFd;
@ -150,7 +150,10 @@ impl FixedIndexReader {
println!("ChunkSize: {}", self.chunk_size);
println!(
"CTime: {}",
Local.timestamp(self.ctime as i64, 0).format("%c")
match Local.timestamp_opt(self.ctime as i64, 0) {
LocalResult::Single(ctime) => ctime.format("%c").to_string(),
_ => (self.ctime as i64).to_string(),
}
);
println!("UUID: {:?}", self.uuid);
}