[pve-devel] [PATCH qemu-server v4 1/2] restore: replace archive format/compression

Alwin Antreich a.antreich at proxmox.com
Wed Apr 22 16:57:55 CEST 2020


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 37c7320..265d4f8 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5627,28 +5627,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') {
@@ -6235,14 +6216,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