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

Alwin Antreich a.antreich at proxmox.com
Wed Apr 8 12:25:54 CEST 2020


format/compression regex to reduce the code duplication, as archive_info
and decompressor_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 510a995..e5bf41b 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5501,28 +5501,9 @@ sub tar_restore_cleanup {
 sub restore_file_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') {
@@ -6109,14 +6090,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::decompressor_info('vma', $comp);
+	my $cmd = $info->{decompressor};
+	push @$cmd, $readfrom;
 	$add_pipe->($cmd);
     }
 
-- 
2.20.1





More information about the pve-devel mailing list