[pve-devel] [PATCH qemu-server v2 1/2] restore: replace archive regex

Alwin Antreich a.antreich at proxmox.com
Fri Jan 31 17:01:00 CET 2020


to reduce the code duplication, as archive_info provides the same
information as well.

Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
 PVE/QemuServer.pm | 36 ++++++------------------------------
 1 file changed, 6 insertions(+), 30 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 7374bf1..ff7dcab 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5879,28 +5879,9 @@ sub tar_restore_cleanup {
 sub restore_archive {
     my ($archive, $vmid, $user, $opts) = @_;
 
-    my $format = $opts->{format};
-    my $comp;
-
-    if ($archive =~ m/\.tgz$/ || $archive =~ m/\.tar\.gz$/) {
-	$format = 'tar' if !$format;
-	$comp = 'gzip';
-    } elsif ($archive =~ m/\.tar$/) {
-	$format = 'tar' if !$format;
-    } elsif ($archive =~ m/.tar.lzo$/) {
-	$format = 'tar' if !$format;
-	$comp = 'lzop';
-    } elsif ($archive =~ m/\.vma$/) {
-	$format = 'vma' if !$format;
-    } elsif ($archive =~ m/\.vma\.gz$/) {
-	$format = 'vma' if !$format;
-	$comp = 'gzip';
-    } elsif ($archive =~ m/\.vma\.lzo$/) {
-	$format = 'vma' if !$format;
-	$comp = 'lzop';
-    } else {
-	$format = 'vma' if !$format; # default
-    }
+    my $info = PVE::Storage::archive_info($archive);
+    my $format = $opts->{format} // $info->{format};
+    my $comp = $info->{compression};
 
     # try to detect archive format
     if ($format eq 'tar') {
@@ -6212,14 +6193,9 @@ sub restore_vma_archive {
     }
 
     if ($comp) {
-	my $cmd;
-	if ($comp eq 'gzip') {
-	    $cmd = ['zcat', $readfrom];
-	} elsif ($comp eq 'lzop') {
-	    $cmd = ['lzop', '-d', '-c', $readfrom];
-	} else {
-	    die "unknown compression method '$comp'\n";
-	}
+	my $info = PVE::Storage::archive_info(undef, $comp, 'vma');
+	my $cmd = $info->{decompressor};
+	push @$cmd, $readfrom;
 	$add_pipe->($cmd);
     }
 
-- 
2.20.1





More information about the pve-devel mailing list