From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 0817961066 for ; Fri, 11 Sep 2020 14:35:28 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id F1AAC24C50 for ; Fri, 11 Sep 2020 14:34:57 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 5DB7424C46 for ; Fri, 11 Sep 2020 14:34:57 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 291D144B6C for ; Fri, 11 Sep 2020 14:34:57 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Fri, 11 Sep 2020 14:34:37 +0200 Message-Id: <20200911123439.1876094-5-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200911123439.1876094-1-f.gruenbichler@proxmox.com> References: <20200911123439.1876094-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.026 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [tools.rs] Subject: [pbs-devel] [PATCH proxmox-backup 4/6] handle invalid mtime when formating entries X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Sep 2020 12:35:28 -0000 otherwise operations like catalog shell panic when viewing pxar archives containing such entries, e.g. with mtime very far ahead into the future. Signed-off-by: Fabian Grünbichler --- src/pxar/tools.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/pxar/tools.rs b/src/pxar/tools.rs index 0fdb033d..2eed0f81 100644 --- a/src/pxar/tools.rs +++ b/src/pxar/tools.rs @@ -8,7 +8,7 @@ use std::path::Path; use anyhow::{bail, format_err, Error}; use nix::sys::stat::Mode; -use pxar::{mode, Entry, EntryKind, Metadata}; +use pxar::{mode, Entry, EntryKind, Metadata, format::StatxTimestamp}; /// Get the file permissions as `nix::Mode` pub fn perms_from_metadata(meta: &Metadata) -> Result { @@ -114,13 +114,19 @@ fn mode_string(entry: &Entry) -> String { ) } -pub fn format_single_line_entry(entry: &Entry) -> String { +fn format_mtime(mtime: &StatxTimestamp) -> String { use chrono::offset::TimeZone; + match chrono::Local.timestamp_opt(mtime.secs, mtime.nanos) { + chrono::LocalResult::Single(mtime) => mtime.format("%Y-%m-%d %H:%M:%S").to_string(), + _ => format!("{}.{}", mtime.secs, mtime.nanos), + } +} + +pub fn format_single_line_entry(entry: &Entry) -> String { let mode_string = mode_string(entry); let meta = entry.metadata(); - let mtime = chrono::Local.timestamp(meta.stat.mtime.secs, meta.stat.mtime.nanos); let (size, link) = match entry.kind() { EntryKind::File { size, .. } => (format!("{}", *size), String::new()), @@ -134,7 +140,7 @@ pub fn format_single_line_entry(entry: &Entry) -> String { "{} {:<13} {} {:>8} {:?}{}", mode_string, format!("{}/{}", meta.stat.uid, meta.stat.gid), - mtime.format("%Y-%m-%d %H:%M:%S"), + format_mtime(&meta.stat.mtime), size, entry.path(), link, @@ -142,12 +148,9 @@ pub fn format_single_line_entry(entry: &Entry) -> String { } pub fn format_multi_line_entry(entry: &Entry) -> String { - use chrono::offset::TimeZone; - let mode_string = mode_string(entry); let meta = entry.metadata(); - let mtime = chrono::Local.timestamp(meta.stat.mtime.secs, meta.stat.mtime.nanos); let (size, link, type_name) = match entry.kind() { EntryKind::File { size, .. } => (format!("{}", *size), String::new(), "file"), @@ -196,6 +199,6 @@ pub fn format_multi_line_entry(entry: &Entry) -> String { mode_string, meta.stat.uid, meta.stat.gid, - mtime.format("%Y-%m-%d %H:%M:%S"), + format_mtime(&meta.stat.mtime), ) } -- 2.20.1