public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH storage] fix #3199: by fixing usage of strftime
Date: Tue, 15 Dec 2020 11:59:29 +0100	[thread overview]
Message-ID: <20201215105929.11873-1-f.ebner@proxmox.com> (raw)

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

This is embarassing...
In a very early version I wanted to parse the date from the backup name, and
when switching to using the ctime and localtime() instead, I forgot to update
the usage of strftime.

 PVE/Storage.pm             |  4 ++--
 test/prune_backups_test.pm | 48 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index c1a21b4..76d17c6 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1697,8 +1697,8 @@ sub prune_mark_backup_group {
     $prune_mark->($prune_list, $keep->{'keep-weekly'}, sub {
 	my ($ctime) = @_;
 	my ($sec, $min, $hour, $day, $month, $year) = localtime($ctime);
-	my $iso_week = int(strftime("%V", $sec, $min, $hour, $day, $month - 1, $year - 1900));
-	my $iso_week_year = int(strftime("%G", $sec, $min, $hour, $day, $month - 1, $year - 1900));
+	my $iso_week = int(strftime("%V", $sec, $min, $hour, $day, $month, $year));
+	my $iso_week_year = int(strftime("%G", $sec, $min, $hour, $day, $month, $year));
 	return "$iso_week/$iso_week_year";
     });
     $prune_mark->($prune_list, $keep->{'keep-monthly'}, sub {
diff --git a/test/prune_backups_test.pm b/test/prune_backups_test.pm
index c69c467..a87c4b3 100644
--- a/test/prune_backups_test.pm
+++ b/test/prune_backups_test.pm
@@ -91,6 +91,23 @@ push @{$mocked_backups_lists->{threeway}}, (
 	'vmid'  => 7654,
     },
 );
+push @{$mocked_backups_lists->{weekboundary}}, (
+    {
+	'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_03-12_18_21.tar.zst",
+	'ctime' => $basetime + (366-31+2)*24*60*60,
+	'vmid'  => 7654,
+    },
+    {
+	'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_04-12_18_21.tar.zst",
+	'ctime' => $basetime + (366-31+3)*24*60*60,
+	'vmid'  => 7654,
+    },
+    {
+	'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_07-12_18_21.tar.zst",
+	'ctime' => $basetime + (366-31+6)*24*60*60,
+	'vmid'  => 7654,
+    },
+);
 my $current_list;
 my $mock_plugin = Test::MockModule->new('PVE::Storage::Plugin');
 $mock_plugin->redefine(list_volumes => sub {
@@ -410,6 +427,37 @@ my $tests = [
 	    },
 	],
     },
+    {
+	description => 'daily=weekly=1,weekboundary',
+	keep => {
+	    'keep-daily' => 1,
+	    'keep-weekly' => 1,
+	},
+	list => 'weekboundary',
+	expected => [
+	    {
+		'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_03-12_18_21.tar.zst",
+		'ctime' => $basetime + (366-31+2)*24*60*60,
+		'type'  => 'qemu',
+		'vmid'  => 7654,
+		'mark'  => 'remove',
+	    },
+	    {
+		'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_04-12_18_21.tar.zst",
+		'ctime' => $basetime + (366-31+3)*24*60*60,
+		'type'  => 'qemu',
+		'vmid'  => 7654,
+		'mark'  => 'keep',
+	    },
+	    {
+		'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_07-12_18_21.tar.zst",
+		'ctime' => $basetime + (366-31+6)*24*60*60,
+		'type'  => 'qemu',
+		'vmid'  => 7654,
+		'mark'  => 'keep',
+	    },
+	],
+    },
 ];
 
 plan tests => scalar @$tests;
-- 
2.20.1





             reply	other threads:[~2020-12-15 10:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-15 10:59 Fabian Ebner [this message]
2020-12-15 13:40 ` [pve-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201215105929.11873-1-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal