* [pve-devel] [PATCH storage] archive_info: use timelocal correctly
@ 2020-07-08 8:22 Fabian Ebner
2020-07-08 8:50 ` [pve-devel] applied: " Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Fabian Ebner @ 2020-07-08 8:22 UTC (permalink / raw)
To: pve-devel
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 <f.ebner@proxmox.com>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pve-devel] applied: Re: [PATCH storage] archive_info: use timelocal correctly
2020-07-08 8:22 [pve-devel] [PATCH storage] archive_info: use timelocal correctly Fabian Ebner
@ 2020-07-08 8:50 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2020-07-08 8:50 UTC (permalink / raw)
To: Proxmox VE development discussion, Fabian Ebner
On 08.07.20 10:22, Fabian Ebner wrote:
> 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 <f.ebner@proxmox.com>
> ---
>
> 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(-)
>
>
applied, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-07-08 8:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-08 8:22 [pve-devel] [PATCH storage] archive_info: use timelocal correctly Fabian Ebner
2020-07-08 8:50 ` [pve-devel] applied: " Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox