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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 69B365BBF8 for ; Wed, 8 Jul 2020 10:22:29 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 55C5B2E2D5 for ; Wed, 8 Jul 2020 10:22:29 +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 944622E2C9 for ; Wed, 8 Jul 2020 10:22:27 +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 53DD142742 for ; Wed, 8 Jul 2020 10:22:27 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Wed, 8 Jul 2020 10:22:19 +0200 Message-Id: <20200708082219.25439-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.400 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. [perl.org, storage.pm] Subject: [pve-devel] [PATCH storage] archive_info: use timelocal correctly X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jul 2020 08:22:29 -0000 Because we always have 4-digit years, we can simply pass the year itself to timelocal instead of subtracting 1900. Like this it will also work for years not in the range 2000-2999. See also: https://perldoc.perl.org/Time/Local.html#Year-Value-Interpretation Signed-off-by: Fabian Ebner --- Hopefully in 3070, Perl isn't full of surprises anymore. PVE/Storage.pm | 2 +- test/archive_info_test.pm | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index bb80b07..ffa1484 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -1404,7 +1404,7 @@ sub archive_info { if ($volid =~ /^(vzdump-${type}-([1-9][0-9]{2,8})-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2}))\.${format_re}$/) { $info->{logfilename} = "$1.log"; $info->{vmid} = int($2); - $info->{ctime} = timelocal($8, $7, $6, $5, $4 - 1, $3 - 1900); + $info->{ctime} = timelocal($8, $7, $6, $5, $4 - 1, $3); $info->{is_std_name} = 1; } else { $info->{is_std_name} = 0; diff --git a/test/archive_info_test.pm b/test/archive_info_test.pm index 2f9811c..7e84b6a 100644 --- a/test/archive_info_test.pm +++ b/test/archive_info_test.pm @@ -18,6 +18,36 @@ my $vmid = 16110; # most of them are created further below my $tests = [ # backup archives + { + description => 'Backup archive, lxc, tgz, future millenium', + archive => "backup/vzdump-lxc-$vmid-3070_01_01-00_00_00.tgz", + expected => { + 'filename' => "vzdump-lxc-$vmid-3070_01_01-00_00_00.tgz", + 'logfilename' => "vzdump-lxc-$vmid-3070_01_01-00_00_00.log", + 'type' => 'lxc', + 'format' => 'tar', + 'decompressor' => ['tar', '-z'], + 'compression' => 'gz', + 'vmid' => $vmid, + 'ctime' => 60*60*24 * (365*1100 + 267), + 'is_std_name' => 1, + }, + }, + { + description => 'Backup archive, lxc, tgz, very old', + archive => "backup/vzdump-lxc-$vmid-1970_01_01-02_00_30.tgz", + expected => { + 'filename' => "vzdump-lxc-$vmid-1970_01_01-02_00_30.tgz", + 'logfilename' => "vzdump-lxc-$vmid-1970_01_01-02_00_30.log", + 'type' => 'lxc', + 'format' => 'tar', + 'decompressor' => ['tar', '-z'], + 'compression' => 'gz', + 'vmid' => $vmid, + 'ctime' => 60*60*2 + 30, + 'is_std_name' => 1, + }, + }, { description => 'Backup archive, lxc, tgz', archive => "backup/vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz", -- 2.20.1