[pve-devel] [PATCH storage v3 6/7] backup: more compact regex for backup filter
Alwin Antreich
a.antreich at proxmox.com
Wed Apr 8 12:26:01 CEST 2020
The more compact form of the regex should allow easier addition of new
file extensions.
Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
PVE/Storage.pm | 4 ++--
PVE/Storage/Plugin.pm | 6 ++++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 0bbd168..46384ff 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -519,7 +519,7 @@ sub path_to_volume_id {
} elsif ($path =~ m!^$privatedir/(\d+)$!) {
my $vmid = $1;
return ('rootdir', "$sid:rootdir/$vmid");
- } elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!) {
+ } elsif ($path =~ m!^$backupdir/([^/]+\.(?:tgz|(?:(?:tar|vma)(?:\.(?:${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)))$!) {
my $name = $1;
return ('iso', "$sid:backup/$name");
}
@@ -1321,7 +1321,7 @@ sub archive_info {
my $info;
my $volid = basename($archive);
- if ($volid =~ /vzdump-(lxc|openvz|qemu)-\d+-(?:\d{4})_(?:\d{2})_(?:\d{2})-(?:\d{2})_(?:\d{2})_(?:\d{2})\.(tgz$|tar|vma)(?:\.(gz|lzo))?$/) {
+ if ($volid =~ /vzdump-(lxc|openvz|qemu)-\d+-(?:\d{4})_(?:\d{2})_(?:\d{2})-(?:\d{2})_(?:\d{2})_(?:\d{2})\.(tgz$|tar|vma)(?:\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?$/) {
$info = decompressor_info($2, $3);
$info->{type} = $1;
} else {
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 0ab44ce..ef6e6de 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -17,6 +17,8 @@ use JSON;
use base qw(PVE::SectionConfig);
+use constant COMPRESSOR_RE => 'gz|lzo';
+
our @COMMON_TAR_FLAGS = qw(
--one-file-system
-p --sparse --numeric-owner --acls
@@ -434,7 +436,7 @@ sub parse_volname {
return ('vztmpl', $1);
} elsif ($volname =~ m!^rootdir/(\d+)$!) {
return ('rootdir', $1, $1);
- } elsif ($volname =~ m!^backup/([^/]+(\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo)))$!) {
+ } elsif ($volname =~ m!^backup/([^/]+(?:\.(?:tgz|(?:(?:tar|vma)(?:\.(?:${\COMPRESSOR_RE}))?))))$!) {
my $fn = $1;
if ($fn =~ m/^vzdump-(openvz|lxc|qemu)-(\d+)-.+/) {
return ('backup', $fn, $2);
@@ -949,7 +951,7 @@ my $get_subdir_files = sub {
} elsif ($tt eq 'backup') {
next if defined($vmid) && $fn !~ m/\S+-$vmid-\S+/;
- next if $fn !~ m!/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!;
+ next if $fn !~ m!/([^/]+\.(tgz|(?:(?:tar|vma)(?:\.(${\COMPRESSOR_RE}))?)))$!;
my $format = $2;
$fn = $1;
--
2.20.1
More information about the pve-devel
mailing list