]> git.proxmox.com Git - pve-storage.git/commitdiff
factoring out regex for vztmpl
authorLorenz Stechauner <l.stechauner@proxmox.com>
Wed, 23 Jun 2021 13:10:15 +0000 (15:10 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 23 Jun 2021 18:19:09 +0000 (20:19 +0200)
stores the regex definition in PVE::Storage.

One test had to be adapted because it tested obsolete code. Namely:
it expects vztmpl to only end with .tar.gz, but the new regex also
includes .tar.xz, there is nothing against allowing .tar.xz files as
vztmpl files.

Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
PVE/API2/Storage/Status.pm
PVE/Storage.pm
PVE/Storage/Plugin.pm
test/path_to_volume_id_test.pm

index 8a36aefb8c5d22d0c4b80eb0f805d78ce99f0a92..70692444c6177b3847508d16719347ca6e3e39c7 100644 (file)
@@ -423,12 +423,12 @@ __PACKAGE__->register_method ({
 
        if ($content eq 'iso') {
            if ($filename !~ m![^/]+$PVE::Storage::iso_extension_re$!) {
-               raise_param_exc({ filename => "missing '.iso' or '.img' extension" });
+               raise_param_exc({ filename => "wrong file extension" });
            }
            $path = PVE::Storage::get_iso_dir($cfg, $param->{storage});
        } elsif ($content eq 'vztmpl') {
-           if ($filename !~ m![^/]+\.tar\.[gx]z$!) {
-               raise_param_exc({ filename => "missing '.tar.gz' or '.tar.xz' extension" });
+           if ($filename !~ m![^/]+$PVE::Storage::vztmpl_extension_re$!) {
+               raise_param_exc({ filename => "wrong file extension" });
            }
            $path = PVE::Storage::get_vztmpl_dir($cfg, $param->{storage});
        } else {
index ace3340179327a252c266c71a52e4c9f463653f1..e3bdffe940653491717726a00948ece8142766f1 100755 (executable)
@@ -101,6 +101,8 @@ PVE::Storage::Plugin->init();
 
 our $iso_extension_re = qr/\.(?:iso|img)/i;
 
+our $vztmpl_extension_re = qr/\.tar\.([gx]z)/i;
+
 #  PVE::Storage utility functions
 
 sub config {
@@ -573,7 +575,7 @@ sub path_to_volume_id {
        } elsif ($path =~ m!^$isodir/([^/]+$iso_extension_re)$!) {
            my $name = $1;
            return ('iso', "$sid:iso/$name");
-       } elsif ($path =~ m!^$tmpldir/([^/]+\.tar\.gz)$!) {
+       } elsif ($path =~ m!^$tmpldir/([^/]+$vztmpl_extension_re)$!) {
            my $name = $1;
            return ('vztmpl', "$sid:vztmpl/$name");
        } elsif ($path =~ m!^$privatedir/(\d+)$!) {
index 31d9e286dc8bf1fe967437df0f7f808ef6cb8aeb..080835f68109338c3daa6e8193dd49cbab2bec2b 100644 (file)
@@ -518,7 +518,7 @@ sub parse_volname {
        return ('images', $name, $vmid, undef, undef, $isBase, $format);
     } elsif ($volname =~ m!^iso/([^/]+$PVE::Storage::iso_extension_re)$!) {
        return ('iso', $1);
-    } elsif ($volname =~ m!^vztmpl/([^/]+\.tar\.[gx]z)$!) {
+    } elsif ($volname =~ m!^vztmpl/([^/]+$PVE::Storage::vztmpl_extension_re)$!) {
        return ('vztmpl', $1);
     } elsif ($volname =~ m!^rootdir/(\d+)$!) {
        return ('rootdir', $1, $1);
@@ -1050,7 +1050,7 @@ my $get_subdir_files = sub {
            $info = { volid => "$sid:iso/$1", format => 'iso' };
 
        } elsif ($tt eq 'vztmpl') {
-           next if $fn !~ m!/([^/]+\.tar\.([gx]z))$!;
+           next if $fn !~ m!/([^/]+$PVE::Storage::vztmpl_extension_re)$!;
 
            $info = { volid => "$sid:vztmpl/$1", format => "t$2" };
 
index 5eee2f6a7172d40efc8d3b5c4151b66ad8972c82..8149c881e2e727085d29924345b18258a4b4d2a1 100644 (file)
@@ -166,12 +166,13 @@ my @tests = (
            'local:snippets/hookscript.pl',
        ],
     },
-
-    # no matches
     {
        description => 'CT template, tar.xz',
        volname     => "$storage_dir/template/cache/debian-10.0-standard_10.0-1_amd64.tar.xz",
-       expected    => [''],
+       expected    => [
+           'vztmpl',
+           'local:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.xz',
+       ],
     },
 
     # no matches, path or files with failures