From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, l.stechauner@proxmox.com
Subject: Re: [pve-devel] [PATCH v2 storage 2/2] storage/plugin: factoring out regex for backup extension re
Date: Fri, 13 Aug 2021 12:10:25 +0200 [thread overview]
Message-ID: <874f05a2-56a8-142b-dc8d-4329aef828c2@proxmox.com> (raw)
In-Reply-To: <20210805073447.1201979-3-l.stechauner@proxmox.com>
Am 05.08.21 um 09:34 schrieb Lorenz Stechauner:
> Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
> ---
> 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;
Please mention in the commit message that this now matches
case-insensitively, which is different from the current behavior.
But matching case-insensitively doesn't work, because at least
decompressor_info() cannot handle uppercase extensions currently.
> +
> # 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;
>
next prev parent reply other threads:[~2021-08-13 10:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-05 7:34 [pve-devel] [PATCH-SERIES v2 storage/manager] factoring out RE for backup extension Lorenz Stechauner
2021-08-05 7:34 ` [pve-devel] [PATCH v2 storage 1/2] storage: rename REs for iso and vztmpl extensions Lorenz Stechauner
2021-08-13 10:09 ` Fabian Ebner
2021-08-16 8:46 ` Lorenz Stechauner
2021-09-01 10:23 ` Fabian Ebner
2021-08-05 7:34 ` [pve-devel] [PATCH v2 storage 2/2] storage/plugin: factoring out regex for backup extension re Lorenz Stechauner
2021-08-13 10:10 ` Fabian Ebner [this message]
2021-08-05 7:34 ` [pve-devel] [PATCH v2 manager 1/1] api: aplinfo: rename REs for iso and vztmpl extensions Lorenz Stechauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874f05a2-56a8-142b-dc8d-4329aef828c2@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=l.stechauner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox