catalog dump: preserve original mtime

even if it can't be handled by chrono. silently replacing it with epoch
0 is confusing..

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2020-09-11 14:34:34 +02:00 committed by Dietmar Maurer
parent 229adeb746
commit 4a363fb4a7

View File

@ -5,7 +5,7 @@ use std::io::{Read, Write, Seek, SeekFrom};
use std::os::unix::ffi::OsStrExt; use std::os::unix::ffi::OsStrExt;
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
use chrono::offset::{TimeZone, Local}; use chrono::offset::{TimeZone, Local, LocalResult};
use pathpatterns::{MatchList, MatchType}; use pathpatterns::{MatchList, MatchType};
use proxmox::tools::io::ReadExt; use proxmox::tools::io::ReadExt;
@ -533,17 +533,17 @@ impl <R: Read + Seek> CatalogReader<R> {
self.dump_dir(&path, pos)?; self.dump_dir(&path, pos)?;
} }
CatalogEntryType::File => { CatalogEntryType::File => {
let dt = Local let mtime_string = match Local.timestamp_opt(mtime as i64, 0) {
.timestamp_opt(mtime as i64, 0) LocalResult::Single(time) => time.to_rfc3339_opts(chrono::SecondsFormat::Secs, false),
.single() // chrono docs say timestamp_opt can only be None or Single! _ => (mtime as i64).to_string(),
.unwrap_or_else(|| Local.timestamp(0, 0)); };
println!( println!(
"{} {:?} {} {}", "{} {:?} {} {}",
etype, etype,
path, path,
size, size,
dt.to_rfc3339_opts(chrono::SecondsFormat::Secs, false), mtime_string,
); );
} }
_ => { _ => {