From b867882aee225f21502ee55a2c9b077f5c302a35 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Wed, 1 Dec 2021 19:47:31 +0100 Subject: [PATCH] finalize: allow to choose gzip or zstd and default to latter zstd shaves of >50 MiB of the final archive and is (in general) faster on decompression too Signed-off-by: Thomas Lamprecht --- PVE/AAB.pm | 30 ++++++++++++++++++++++++------ aab | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/PVE/AAB.pm b/PVE/AAB.pm index dcc62d4..2de341c 100644 --- a/PVE/AAB.pm +++ b/PVE/AAB.pm @@ -636,7 +636,19 @@ sub write_config { } sub finalize { - my ($self) = @_; + my ($self, $compressor) = @_; + + my $use_zstd = 1; + if (defined($compressor)) { + if ($compressor =~ /^\s*--zstd?\s*$/) { + $use_zstd = 1; + } elsif ($compressor =~ /^\s*--(?:gz|gzip)\s*$/) { + $use_zstd = 0; # just boolean for now.. + } else { + die "unkown compressor '$compressor'!\n"; + } + } + my $rootdir = $self->{rootfs}; print "Stopping container...\n"; @@ -663,18 +675,24 @@ sub finalize { $self->logmsg ("creating final appliance archive\n"); + my $compressor_ext = $use_zstd ? 'zst' : 'gz'; + my $target = "$self->{targetname}.tar"; unlink $target; - unlink "$target.gz"; + unlink "$target.$compressor_ext"; $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info"); $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info ."); - $self->logmsg ("compressing archive\n"); - $self->run_command ("gzip $target"); + $self->logmsg ("compressing archive ($compressor_ext)\n"); + if ($use_zstd) { + $self->run_command ("zstd -19 --rm $target"); + } else { + $self->run_command ("gzip -9 $target"); + } - my $target_size = int(-s "$target.gz") >> 20; - $self->logmsg ("created '$target.gz' with size: $target_size MB\n"); + my $target_size = int(-s "$target.$compressor_ext") >> 20; + $self->logmsg ("created '$target.$compressor_ext' with size: $target_size MB\n"); } sub enter { diff --git a/aab b/aab index 35e14e5..b15ad16 100755 --- a/aab +++ b/aab @@ -111,7 +111,7 @@ eval { } elsif ($cmd eq 'finalize') { - $aab->finalize(); + $aab->finalize(@ARGV); } elsif ($cmd eq 'install') { -- 2.39.2