For less and cleaner code, use a hash for de-compressor commands instead
of the 'long' if-elsif statement.

Signed-off-by: Alwin Antreich <[email protected]>
---
 PVE/Storage.pm | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 6953b3f..537259a 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1380,19 +1380,17 @@ sub decompressor_info {
        }
     }
 
+    my $decompressor = {
+       'gz'   => ["zcat", $archive],
+       'lzo'  => ["lzop", "-d", "-c", $archive],
+       'zst'  => ["zstd", "-q", "-d", "-c", $archive],
+    };
+
     my $cmd;
-    if (defined($comp)) {
-       if ($comp eq 'gz') {
-           $cmd = ["zcat", $archive];
-       } elsif ($comp eq 'lzo') {
-           $cmd = ["lzop", "-d", "-c", $archive];
-       } elsif ($comp eq 'zst') {
-           $cmd = ["zstd", "-q", "-d", "-c", $archive];
-       } else {
-           die "unknown compression method '$comp'\n" if !$noerr;
-       }
+    if (defined($comp) && $decompressor->{$comp}) {
+       $cmd = $decompressor->{$comp};
     } else {
-       die "compression type not set\n" if !$noerr;
+       die "compression method unknown, '$comp'\n" if !$noerr;
     }
 
     pop(@$cmd) if !defined($archive);
-- 
2.11.0


_______________________________________________
pve-devel mailing list
[email protected]
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to