]> git.proxmox.com Git - pve-manager.git/commitdiff
fix maxfiles behavior
authorFabian Ebner <f.ebner@proxmox.com>
Mon, 9 Nov 2020 08:56:33 +0000 (09:56 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 16 Nov 2020 17:18:32 +0000 (18:18 +0100)
Commit b64dd8c8a56c424b4cfe8cb8ef0841e49ba38c03 hard-coded 0 as the default
for maxfiles in the --storage case, but the actual default should be the
value from read_vzdump_defaults(), which obtains the value from
/etc/vzdump.conf or the VZDump schema if the value has not been modified in
that file. The initial default from the schema is 1, not 0.
Tested on PVE 6.1 to verify that behavior.

Move the sanity check for zero-ness to where we have the final value for
maxfiles. Like this, we also have an implicit definedness check and more
importantly, it is more future-proof in case we ever allow maxfiles 0 in the
VZDump schema itself.

Also, force conversion to int to be extra safe.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/VZDump.pm

index 1096d5942c513769bf33b037e97e87df3d63f172..fa387299aeba5961e6fe501355e759f64a0ead9d 100644 (file)
@@ -476,11 +476,7 @@ sub new {
 
            if (!defined($opts->{'prune-backups'}) && !defined($opts->{maxfiles})) {
                $opts->{'prune-backups'} = $info->{'prune-backups'};
-               $opts->{maxfiles} = $info->{maxfiles} // 0;
-               if ($opts->{maxfiles} == 0) {
-                   # zero means keep all, so avoid triggering any remove code path to be safe
-                   $opts->{remove} = 0;
-               }
+               $opts->{maxfiles} = $info->{maxfiles};
            }
        }
     } elsif ($opts->{dumpdir}) {
@@ -492,7 +488,13 @@ sub new {
 
     if (!defined($opts->{'prune-backups'})) {
        my $maxfiles = delete $opts->{maxfiles} // $defaults->{maxfiles};
-       $opts->{'prune-backups'} = { 'keep-last' => $maxfiles } if $maxfiles;
+       $maxfiles = int($maxfiles); # shouldn't be necessary, but be safe
+       if ($maxfiles) {
+           $opts->{'prune-backups'} = { 'keep-last' => $maxfiles };
+       } else {
+           # maxfiles being zero means keep all, so avoid triggering any remove code path to be safe
+           $opts->{remove} = 0;
+       }
     }
 
     if ($opts->{tmpdir} && ! -d $opts->{tmpdir}) {