From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id BFD486B9CF for ; Thu, 5 Aug 2021 09:35:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A825A2718E for ; Thu, 5 Aug 2021 09:35:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 4F4FA27182 for ; Thu, 5 Aug 2021 09:35:16 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1E15942DF7 for ; Thu, 5 Aug 2021 09:35:06 +0200 (CEST) From: Lorenz Stechauner To: pve-devel@lists.proxmox.com Date: Thu, 5 Aug 2021 09:34:46 +0200 Message-Id: <20210805073447.1201979-3-l.stechauner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210805073447.1201979-1-l.stechauner@proxmox.com> References: <20210805073447.1201979-1-l.stechauner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.486 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment T_SPF_HELO_TEMPERROR 0.01 SPF: test of HELO record failed (temperror) T_SPF_TEMPERROR 0.01 SPF: test of record failed (temperror) Subject: [pve-devel] [PATCH v2 storage 2/2] storage/plugin: factoring out regex for backup extension re X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Aug 2021 07:35:53 -0000 Signed-off-by: Lorenz Stechauner --- PVE/Storage.pm | 12 +++++++----- PVE/Storage/Plugin.pm | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index b5c2460..9bc799d 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -108,6 +108,8 @@ our $ISO_EXT_RE_0 = qr/\.(?:iso|img)/i; our $VZTMPL_EXT_RE_1 = qr/\.tar\.([gx]z)/i; +our $BACKUP_EXT_RE_2 = qr/\.(tgz|(?:tar|vma)(?:\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)/i; + # PVE::Storage utility functions sub config { @@ -586,7 +588,7 @@ sub path_to_volume_id { } elsif ($path =~ m!^$privatedir/(\d+)$!) { my $vmid = $1; return ('rootdir', "$sid:rootdir/$vmid"); - } elsif ($path =~ m!^$backupdir/([^/]+\.(?:tgz|(?:(?:tar|vma)(?:\.(?:${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)))$!) { + } elsif ($path =~ m!^$backupdir/([^/]+$BACKUP_EXT_RE_2)$!) { my $name = $1; return ('backup', "$sid:backup/$name"); } elsif ($path =~ m!^$snippetsdir/([^/]+)$!) { @@ -1471,15 +1473,15 @@ sub archive_info { my $info; my $volid = basename($archive); - if ($volid =~ /^(vzdump-(lxc|openvz|qemu)-.+\.(tgz$|tar|vma)(?:\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)$/) { + if ($volid =~ /^(vzdump-(lxc|openvz|qemu)-.+$BACKUP_EXT_RE_2)$/) { my $filename = "$1"; # untaint - my ($type, $format, $comp) = ($2, $3, $4); - my $format_re = defined($comp) ? "$format.$comp" : "$format"; + my ($type, $extension, $comp) = ($2, $3, $4); + (my $format = $extension) =~ s/\..*//; $info = decompressor_info($format, $comp); $info->{filename} = $filename; $info->{type} = $type; - if ($volid =~ /^(vzdump-${type}-([1-9][0-9]{2,8})-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2}))\.${format_re}$/) { + if ($volid =~ /^(vzdump-${type}-([1-9][0-9]{2,8})-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2}))\.${extension}$/) { $info->{logfilename} = "$1.log"; $info->{vmid} = int($2); $info->{ctime} = timelocal($8, $7, $6, $5, $4 - 1, $3); diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm index 502951f..b2ffc26 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -522,7 +522,7 @@ sub parse_volname { return ('vztmpl', $1); } elsif ($volname =~ m!^rootdir/(\d+)$!) { return ('rootdir', $1, $1); - } elsif ($volname =~ m!^backup/([^/]+(?:\.(?:tgz|(?:(?:tar|vma)(?:\.(?:${\COMPRESSOR_RE}))?))))$!) { + } elsif ($volname =~ m!^backup/([^/]+$PVE::Storage::BACKUP_EXT_RE_2)$!) { my $fn = $1; if ($fn =~ m/^vzdump-(openvz|lxc|qemu)-(\d+)-.+/) { return ('backup', $fn, $2); @@ -1055,7 +1055,7 @@ my $get_subdir_files = sub { $info = { volid => "$sid:vztmpl/$1", format => "t$2" }; } elsif ($tt eq 'backup') { - next if $fn !~ m!/([^/]+\.(tgz|(?:(?:tar|vma)(?:\.(${\COMPRESSOR_RE}))?)))$!; + next if $fn !~ m!/([^/]+$PVE::Storage::BACKUP_EXT_RE_2)$!; my $original = $fn; my $format = $2; $fn = $1; -- 2.30.2