]> git.proxmox.com Git - pve-storage.git/commitdiff
plugin: simplify and fix create-base-path vs mkdir logic
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 5 Jun 2023 09:17:27 +0000 (11:17 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 5 Jun 2023 09:17:27 +0000 (11:17 +0200)
In the previous code, if `create-base-path` was explicitly
set to false, it would be treated the same as if it was
undef, falling through to whatever 'mkdir' was.

Instead, the new options should always be preferred, and the
logic can be simplified to a single line.

Here's the table showing the difference, 'u' being 'undef':

config: mkdir:  u 0 1 u 0 1 u 0 1
        create: u u u 0 0 0 1 1 1
        =========================
mkpath: old:    1 0 1 0 0 1 1 1 1
        new:    1 0 1 0 0 0 1 1 1

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/PVE/Storage/Plugin.pm

index 34d830e7f56f82554b18bbd71ad5f8ca25812c85..1f0382dec16c5104041b949545718bc5fcb18c54 100644 (file)
@@ -1707,15 +1707,9 @@ sub config_aware_base_mkdir {
     my ($class, $scfg, $path) = @_;
 
     # FIXME the mkdir parameter is deprecated and create-base-path should be used
-    my $mkpath = 0;
-    if (!defined($scfg->{'create-base-path'}) && !defined($scfg->{mkdir})) {
-       $mkpath = 1;
-    } elsif (defined($scfg->{'create-base-path'}) && $scfg->{'create-base-path'}) {
-       $mkpath = 1;
-    } elsif ($scfg->{mkdir}) {
-       $mkpath = 1;
+    if ($scfg->{'create-base-path'} // $scfg->{mkdir} // 1) {
+       mkpath($path);
     }
-    mkpath $path if $mkpath;
 }
 
 1;