]> git.proxmox.com Git - proxmox-backup.git/commitdiff
catalog dump: preserve original mtime
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 11 Sep 2020 12:34:34 +0000 (14:34 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 11 Sep 2020 13:43:54 +0000 (15:43 +0200)
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>
src/backup/catalog.rs

index bc2e471e1649522790f0047b7ec612dbe0fef83d..85a3262322e79dd1a4511bcc2c388ac115e123e9 100644 (file)
@@ -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 <R: Read + Seek> CatalogReader<R> {
                     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,
                     );
                 }
                 _ => {