From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 515FB1FF0AA for ; Tue, 17 Nov 2026 21:43:43 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6B3C121681; Tue, 17 Nov 2026 21:41:02 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v3 25/51] tree-wide: replace usages of inline regexes for snippets with parsers Date: Tue, 17 Nov 2026 21:38:57 +0100 Message-ID: <20261117203953.913035-26-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117203953.913035-1-m.carrara@proxmox.com> References: <20261117203953.913035-1-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794948045950 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.258 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 73AQC7ZZTYYXRBRUPAW25PABWNXCVCUA X-Message-ID-Hash: 73AQC7ZZTYYXRBRUPAW25PABWNXCVCUA X-MailFrom: m.carrara@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Wolfgang Bumiller X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add support for the 'snippets' volume type in `PVE::Storage::Common::Parse`. Also add corresponding test cases. Use the module's parsing functions to replace parsing a snippet file's name via regexes or the `basename()` function. Signed-off-by: Max R. Carrara --- src/PVE/Storage.pm | 4 +-- src/PVE/Storage/Common/Parse.pm | 8 ++++++ src/PVE/Storage/Common/test/parser_tests.pl | 29 ++++++++++++++++++++- src/PVE/Storage/Plugin.pm | 11 +++++--- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm index bdd8e445..5d8413a9 100755 --- a/src/PVE/Storage.pm +++ b/src/PVE/Storage.pm @@ -823,13 +823,11 @@ sub path_to_volume_id { if ($vtype eq 'backup') { return ($vtype, parse_abs_path_as_volid($sid, $scfg, $path, $vtype)); } if ($vtype eq 'snippets') { - return if $filename !~ m!^/([^/]+)$!; - my $name = $1; - return ($vtype, "$sid:snippets/$name"); + return ($vtype, parse_abs_path_as_volid($sid, $scfg, $path, $vtype)); } if ($vtype eq 'import') { return if $filename !~ m!^/(${SAFE_CHAR_CLASS_RE}+${IMPORT_EXT_RE_1})$!; my $name = $1; diff --git a/src/PVE/Storage/Common/Parse.pm b/src/PVE/Storage/Common/Parse.pm index 73f4e2bc..ece0dac9 100644 --- a/src/PVE/Storage/Common/Parse.pm +++ b/src/PVE/Storage/Common/Parse.pm @@ -117,20 +117,28 @@ my $RE_BACKUP_FILE_PATH = qr! ) ) ) !xn; +my $RE_SNIPPETS_FILE_PATH = qr! + (? + (? [^/]+ ) + ) +!xn; + my $RE_FILE_PATH_FOR_VTYPE = { iso => qr/^$RE_ISO_FILE_PATH$/, vztmpl => qr/^$RE_VZTMPL_FILE_PATH$/, backup => qr/^$RE_BACKUP_FILE_PATH$/, + snippets => qr/^$RE_SNIPPETS_FILE_PATH$/, }; my $RE_VOLNAME_FOR_VTYPE = { iso => qr/^$RE_ISO_FILE_PATH$/, vztmpl => qr/^$RE_VZTMPL_FILE_PATH$/, backup => qr/^$RE_BACKUP_FILE_PATH$/, + snippets => qr/^$RE_SNIPPETS_FILE_PATH$/, }; my sub contains_parent_dir($path) { return $path =~ $RE_CONTAINS_PARENT_DIR; } diff --git a/src/PVE/Storage/Common/test/parser_tests.pl b/src/PVE/Storage/Common/test/parser_tests.pl index bfb17bbc..812a466f 100755 --- a/src/PVE/Storage/Common/test/parser_tests.pl +++ b/src/PVE/Storage/Common/test/parser_tests.pl @@ -464,10 +464,34 @@ my $volname_cases_backup_invalid = [ }, expected => undef, }, ]; +my $volname_cases_snippets_valid = [ + # plain files + { + path => 'hookscript.pl', + expected => { + file => 'hookscript.pl', + 'disk-path' => 'hookscript.pl', + path => 'hookscript.pl', + vtype => 'snippets', + volname => 'snippets/hookscript.pl', + }, + }, + { + path => 'userconfig.yaml', + expected => { + file => 'userconfig.yaml', + 'disk-path' => 'userconfig.yaml', + path => 'userconfig.yaml', + vtype => 'snippets', + volname => 'snippets/userconfig.yaml', + }, + }, +]; + my $volname_cases_newline_invalid = [ { description => "Trailing newline (iso)", args => { path => "debian.iso\n", @@ -492,11 +516,14 @@ my $volname_cases_newline_invalid = [ expected => undef, }, ]; my $cases_valid_all = [ - $volname_cases_iso_valid, $volname_cases_vztmpl_valid, $volname_cases_backup_valid, + $volname_cases_iso_valid, + $volname_cases_vztmpl_valid, + $volname_cases_backup_valid, + $volname_cases_snippets_valid, ]; my $cases_invalid_all = [ $volname_cases_iso_invalid, $volname_cases_vztmpl_invalid, diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index e3d7367d..8b4f9dde 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -913,14 +913,14 @@ sub parse_volname { } if ($vtype eq 'backup') { return ($vtype, $volume_path, $parts->{vmid}, undef, undef, undef, 'raw'); } - } - if ($volname =~ m!^snippets/([^/]+)$!) { - return ('snippets', $1, undef, undef, undef, undef, 'raw'); + if ($vtype eq 'snippets') { + return ($vtype, $volume_path, undef, undef, undef, undef, 'raw'); + } } if ($volname =~ m!^import/(${PVE::Storage::SAFE_CHAR_WITH_WHITESPACE_CLASS_RE}+\.ova\/${PVE::Storage::OVA_CONTENT_RE_1})$! ) { @@ -1961,12 +1961,15 @@ my sub get_subdir_files { return $info; } if ($vtype eq 'snippets') { + my $parts = parse_abs_path_as_volid_parts($storeid, $scfg, $path, $vtype); + return if !defined($parts); + return { - volid => "$storeid:snippets/" . basename($filename), + volid => $parts->{volid}, format => 'snippet', }; } if ($vtype eq 'import') { -- 2.47.3