From 4a363fb4a73f002eae66aa80a4da7a2532db5fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Fri, 11 Sep 2020 14:34:34 +0200 Subject: [PATCH] catalog dump: preserve original mtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit even if it can't be handled by chrono. silently replacing it with epoch 0 is confusing.. Signed-off-by: Fabian Grünbichler --- src/backup/catalog.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backup/catalog.rs b/src/backup/catalog.rs index bc2e471e..85a32623 100644 --- a/src/backup/catalog.rs +++ b/src/backup/catalog.rs @@ -5,7 +5,7 @@ use std::io::{Read, Write, Seek, SeekFrom}; use std::os::unix::ffi::OsStrExt; use anyhow::{bail, format_err, Error}; -use chrono::offset::{TimeZone, Local}; +use chrono::offset::{TimeZone, Local, LocalResult}; use pathpatterns::{MatchList, MatchType}; use proxmox::tools::io::ReadExt; @@ -533,17 +533,17 @@ impl CatalogReader { self.dump_dir(&path, pos)?; } CatalogEntryType::File => { - let dt = Local - .timestamp_opt(mtime as i64, 0) - .single() // chrono docs say timestamp_opt can only be None or Single! - .unwrap_or_else(|| Local.timestamp(0, 0)); + let mtime_string = match Local.timestamp_opt(mtime as i64, 0) { + LocalResult::Single(time) => time.to_rfc3339_opts(chrono::SecondsFormat::Secs, false), + _ => (mtime as i64).to_string(), + }; println!( "{} {:?} {} {}", etype, path, size, - dt.to_rfc3339_opts(chrono::SecondsFormat::Secs, false), + mtime_string, ); } _ => {