On 6/14/19 3:37 PM, Alwin Antreich wrote:
> This patch removes the code duplication from extract_vzdump_config_vma,
> as it has been factored out for wider use.
> 
> With the introduction of the zstd decompression, most parts of this code
> has been used also for the CT backup extraction and was previously
> duplicated.
> 
> Signed-off-by: Alwin Antreich <[email protected]>
> ---
>  PVE/Storage.pm | 50 +++-----------------------------------------------
>  1 file changed, 3 insertions(+), 47 deletions(-)

please factor this out before 1/3 in an independent patch so that one can
sees the real refactoring.
> 
> diff --git a/PVE/Storage.pm b/PVE/Storage.pm
> index f3c50ca..6953b3f 100755
> --- a/PVE/Storage.pm
> +++ b/PVE/Storage.pm
> @@ -1474,58 +1474,14 @@ sub extract_vzdump_config_tar {
>  
>  sub extract_vzdump_config_vma {
>      my ($archive, $comp) = @_;
> -
> -    my $cmd;
>      my $raw = '';
> -    my $out = sub {
> -     my $output = shift;
> -     $raw .= "$output\n";
> -    };
> -
>  
>      if ($comp) {
> -     my $uncomp;
> -     if ($comp eq 'gz') {
> -         $uncomp = ["zcat", $archive];
> -     } elsif ($comp eq 'lzo') {
> -         $uncomp = ["lzop", "-d", "-c", $archive];
> -     } elsif ($comp eq 'zst') {
> -         $uncomp = ["zstd", "-q", "-d", "-c", $archive];
> -     } else {
> -         die "unknown compression method '$comp'\n";
> -     }
> -     $cmd = [$uncomp, ["vma", "config", "-"]];
> -
> -     # in some cases, lzop/zcat exits with 1 when its stdout pipe is
> -     # closed early by vma, detect this and ignore the exit code later
> -     my $broken_pipe;
> -     my $errstring;
> -     my $err = sub {
> -         my $output = shift;
> -         if ($output =~ m/lzop: Broken pipe: <stdout>/ || $output =~ m/gzip: 
> stdout: Broken pipe/ || $output =~ m/Error 70 : Write error :/) {
> -             $broken_pipe = 1;
> -         } elsif (!defined ($errstring) && $output !~ m/^\s*$/) {
> -             $errstring = "Failed to extract config from VMA archive: 
> $output\n";
> -         }
> -     };
> -
> -     # in other cases, the pipeline will exit with exit code 141
> -     # because of the broken pipe, handle / ignore this as well
> -     my $rc;
> -     eval {
> -         $rc = PVE::Tools::run_command($cmd, outfunc => $out, errfunc => 
> $err, noerr => 1);
> -     };
> -     my $rerr = $@;
> -
> -     # use exit code if no stderr output and not just broken pipe
> -     if (!$errstring && !$broken_pipe && $rc != 0 && $rc != 141) {
> -         die "$rerr\n" if $rerr;
> -         die "config extraction failed with exit code $rc\n";
> -     }
> -     die "$errstring\n" if $errstring;
> +     my $uncomp = decompressor_info($archive, $comp);
> +     $raw = extract_from_archive([$uncomp, ["vma", "config", "-"]]);
>      } else {
>       # simple case without compression and weird piping behaviour
> -     PVE::Tools::run_command(["vma", "config", $archive], outfunc => $out);
> +     $raw = extract_from_archive(["vma", "config", $archive]);
>      }
>  
>      return wantarray ? ($raw, undef) : $raw;
> 


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

Reply via email to