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 DB2E91FF0AB for ; Wed, 23 Sep 2026 17:16:42 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 4FFF22162C; Wed, 23 Sep 2026 17:16:29 +0200 (CEST) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v2 46/50] fix #2884: support nested subdir scanning for 'snippets' vtype Date: Wed, 23 Sep 2026 17:16:06 +0200 Message-ID: <20260923151611.544333-3-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260923151611.544333-1-m.carrara@proxmox.com> References: <20260923150606.531239-1-m.carrara@proxmox.com> <20260923151611.544333-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: 1790176575932 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.372 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: 3TAFTTUCDPBR55RNUTNCV6JEROBPQ35J X-Message-ID-Hash: 3TAFTTUCDPBR55RNUTNCV6JEROBPQ35J 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 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 parsing nested subdirectories for the 'snippets' volume type by adapting its corresponding regex used by parsing helpers. Add additional test cases wherever applicable to account for nested subdirectories for 'snippets' volumes, as was done for the 'iso' and 'vztmpl' volume types. Originally-by: Noel Ullreich Signed-off-by: Max R. Carrara --- src/PVE/Storage/Common/Parse.pm | 3 +- src/PVE/Storage/Common/test/parser_tests.pl | 52 ++++++++++++++ src/PVE/Storage/Plugin.pm | 4 +- src/test/filesystem_path_test.pm | 16 +++++ src/test/list_volumes_test.pm | 78 +++++++++++++++++++++ src/test/parse_volname_test.pm | 52 ++++++++++++++ src/test/path_to_volume_id_test.pm | 7 ++ 7 files changed, 209 insertions(+), 3 deletions(-) diff --git a/src/PVE/Storage/Common/Parse.pm b/src/PVE/Storage/Common/Parse.pm index 86787e75..e665f081 100644 --- a/src/PVE/Storage/Common/Parse.pm +++ b/src/PVE/Storage/Common/Parse.pm @@ -129,6 +129,7 @@ my $RE_BACKUP_FILE_PATH = qr! my $RE_SNIPPETS_FILE_PATH = qr! (? + (? $RE_DIRECTORY_COMPONENTS )? (? [^/]+ ) ) !xn; @@ -329,7 +330,7 @@ These are: Volume types that support subdirectories in their C part also have a C part if a subdirectory is specified. This is currently limited to the -C and C volume types. +C, C and C volume types. The following volume types have more specific parts in addition to the common ones: diff --git a/src/PVE/Storage/Common/test/parser_tests.pl b/src/PVE/Storage/Common/test/parser_tests.pl index 7508d0e5..a5402390 100755 --- a/src/PVE/Storage/Common/test/parser_tests.pl +++ b/src/PVE/Storage/Common/test/parser_tests.pl @@ -498,6 +498,57 @@ my $volname_cases_snippets_valid = [ volname => 'snippets/userconfig.yaml', }, }, + + # subdirectories + { + path => 'subdir/hookscript.pl', + expected => { + file => 'hookscript.pl', + dir => 'subdir', + 'disk-path' => 'subdir/hookscript.pl', + path => 'subdir/hookscript.pl', + vtype => 'snippets', + volname => 'snippets/subdir/hookscript.pl', + }, + }, + { + path => 'deeply/nested/subdir/hookscript.pl', + expected => { + file => 'hookscript.pl', + dir => 'deeply/nested/subdir', + 'disk-path' => 'deeply/nested/subdir/hookscript.pl', + path => 'deeply/nested/subdir/hookscript.pl', + vtype => 'snippets', + volname => 'snippets/deeply/nested/subdir/hookscript.pl', + }, + }, +]; + +my $volname_cases_snippets_invalid = [ + { + description => "Parent dir reference in path (beginning) (snippets)", + args => { + path => '../hookscript.pl', + vtype => 'snippets', + }, + expected => undef, + }, + { + description => "Parent dir reference in path (middle) (snippets)", + args => { + path => 'subdir/../hookscript.pl', + vtype => 'snippets', + }, + expected => undef, + }, + { + description => "Parent dir reference in path (end) (snippets)", + args => { + path => 'subdir/hookscript.pl/..', + vtype => 'snippets', + }, + expected => undef, + }, ]; my $volname_cases_import_valid = [ @@ -597,6 +648,7 @@ my $cases_invalid_all = [ $volname_cases_iso_invalid, $volname_cases_vztmpl_invalid, $volname_cases_backup_invalid, + $volname_cases_snippets_invalid, $volname_cases_import_invalid, ]; diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 2e22e6b7..d011417e 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -236,7 +236,7 @@ my $defaultData = { }, 'max-scan-depth' => { description => "Maximum depth of subdirectories to traverse when searching for" - . " ISOs and container templates in directories.", + . " ISOs, container templates and snippets in directories.", type => 'integer', default => 0, minimum => 0, @@ -1864,7 +1864,7 @@ sub list_volumes { } if ($type eq 'snippets') { - return get_subdir_files($storeid, $scfg, 'snippets', undef); + return get_subdir_files($storeid, $scfg, 'snippets', undef, $depth); } if ($type eq 'import') { diff --git a/src/test/filesystem_path_test.pm b/src/test/filesystem_path_test.pm index b5c1ab33..ff6dffe1 100644 --- a/src/test/filesystem_path_test.pm +++ b/src/test/filesystem_path_test.pm @@ -82,6 +82,22 @@ my $tests = [ 'backup', ], }, + { + volname => 'snippets/userconfig.yaml', + snapname => undef, + expected => ["$DEFAULT_STORAGE_DIR/snippets/userconfig.yaml", undef, 'snippets'], + }, + { + volname => 'snippets/hookscript.pl', + snapname => undef, + expected => ["$DEFAULT_STORAGE_DIR/snippets/hookscript.pl", undef, 'snippets'], + }, + { + volname => 'snippets/foo/bar/baz/something.txt', + snapname => undef, + expected => + ["$DEFAULT_STORAGE_DIR/snippets/foo/bar/baz/something.txt", undef, 'snippets'], + }, ]; my sub run_tests($tests) { diff --git a/src/test/list_volumes_test.pm b/src/test/list_volumes_test.pm index 4dcadb87..d0b054c9 100644 --- a/src/test/list_volumes_test.pm +++ b/src/test/list_volumes_test.pm @@ -1272,6 +1272,24 @@ my $test_param_list = [ "$DEFAULT_STORAGE_PATH/template/cache/1/2/3/4/5/some-lxc-template.tar.gz", expected => undef, }, + { + file => "$DEFAULT_STORAGE_PATH/snippets/some-hookscript.pl", + expected => { + content => 'snippets', + ctime => $DEFAULT_CTIME, + format => 'snippet', + size => $DEFAULT_SIZE, + volid => 'local:snippets/some-hookscript.pl', + }, + }, + { + file => "$DEFAULT_STORAGE_PATH/snippets/1/some-hookscript.pl", + expected => undef, + }, + { + file => "$DEFAULT_STORAGE_PATH/snippets/1/2/3/4/5/some-hookscript.pl", + expected => undef, + }, ], }, { @@ -1342,6 +1360,31 @@ my $test_param_list = [ file => "$DEFAULT_STORAGE_PATH/template/cache/1/2/some-lxc-template.tar.gz", expected => undef, }, + { + file => "$DEFAULT_STORAGE_PATH/snippets/some-hookscript.pl", + expected => { + content => 'snippets', + ctime => $DEFAULT_CTIME, + format => 'snippet', + size => $DEFAULT_SIZE, + volid => 'local:snippets/some-hookscript.pl', + }, + }, + { + file => "$DEFAULT_STORAGE_PATH/snippets/1/some-hookscript.pl", + expected => { + content => 'snippets', + ctime => $DEFAULT_CTIME, + format => 'snippet', + size => $DEFAULT_SIZE, + volid => 'local:snippets/1/some-hookscript.pl', + }, + }, + { + # Exceeds max-scan-depth + file => "$DEFAULT_STORAGE_PATH/snippets/1/2/some-hookscript.pl", + expected => undef, + }, ], }, { @@ -1434,6 +1477,41 @@ my $test_param_list = [ "$DEFAULT_STORAGE_PATH/template/cache/1/2/3/4/5/6/some-lxc-template.tar.gz", expected => undef, }, + { + file => "$DEFAULT_STORAGE_PATH/snippets/some-hookscript.pl", + expected => { + content => 'snippets', + ctime => $DEFAULT_CTIME, + format => 'snippet', + size => $DEFAULT_SIZE, + volid => 'local:snippets/some-hookscript.pl', + }, + }, + { + file => "$DEFAULT_STORAGE_PATH/snippets/1/some-hookscript.pl", + expected => { + content => 'snippets', + ctime => $DEFAULT_CTIME, + format => 'snippet', + size => $DEFAULT_SIZE, + volid => 'local:snippets/1/some-hookscript.pl', + }, + }, + { + file => "$DEFAULT_STORAGE_PATH/snippets/1/2/3/4/5/some-hookscript.pl", + expected => { + content => 'snippets', + ctime => $DEFAULT_CTIME, + format => 'snippet', + size => $DEFAULT_SIZE, + volid => 'local:snippets/1/2/3/4/5/some-hookscript.pl', + }, + }, + { + # Exceeds max-scan-depth + file => "$DEFAULT_STORAGE_PATH/snippets/1/2/3/4/5/6/some-hookscript.pl", + expected => undef, + }, ], }, ]; diff --git a/src/test/parse_volname_test.pm b/src/test/parse_volname_test.pm index b90815c2..0a425ee2 100644 --- a/src/test/parse_volname_test.pm +++ b/src/test/parse_volname_test.pm @@ -372,10 +372,62 @@ my $tests = [ volname => "snippets/$file_name", expected => ['snippets', $file_name, undef, undef, undef, undef, 'raw'], }, + { + description => "Snippets, $file_name, subdirectory", + volname => "snippets/foo/$file_name", + expected => ['snippets', "foo/$file_name", undef, undef, undef, undef, 'raw'], + }, + { + description => "Snippets, $file_name, nested subdirectories", + volname => "snippets/foo/bar/baz/$file_name", + expected => + ['snippets', "foo/bar/baz/$file_name", undef, undef, undef, undef, 'raw'], + }, + { + description => "Snippets, $file_name, subdirectory with same name as file", + volname => "snippets/$file_name/$file_name", + expected => + ['snippets', "$file_name/$file_name", undef, undef, undef, undef, 'raw'], + }, ); push($tests->@*, @extra_tests); } + + # Failed tests + { + my $file_name = "some-file.txt"; + + my @extra_failed_tests = ( + { + description => + "Snippets, $file_name, parent directory reference before volume type prefix", + volname => "../snippets/$file_name", + expected => "unable to parse directory volume name '../snippets/$file_name'\n", + }, + { + description => + "Snippets, $file_name, parent directory reference at beginning of volume path", + volname => "snippets/../$file_name", + expected => "unable to parse directory volume name 'snippets/../$file_name'\n", + }, + { + description => + "Snippets, $file_name, parent directory reference at end of volume path", + volname => "snippets/$file_name/..", + expected => "unable to parse directory volume name 'snippets/$file_name/..'\n", + }, + { + description => + "Snippets, $file_name, parent directory reference between dir components of volume path", + volname => "snippets/foo/../bar/$file_name", + expected => + "unable to parse directory volume name 'snippets/foo/../bar/$file_name'\n", + }, + ); + + push($tests->@*, @extra_failed_tests); + } } # Test cases for import files diff --git a/src/test/path_to_volume_id_test.pm b/src/test/path_to_volume_id_test.pm index 4dfc68e1..d22f6272 100644 --- a/src/test/path_to_volume_id_test.pm +++ b/src/test/path_to_volume_id_test.pm @@ -181,6 +181,13 @@ my $tests = [ 'snippets', 'local:snippets/hookscript.pl', ], }, + { + description => 'Snippets, arbitrary file, nested subdirectories', + file => "$DEFAULT_STORAGE_DIR/snippets/foo/bar/baz/something.txt", + expected => [ + 'snippets', 'local:snippets/foo/bar/baz/something.txt', + ], + }, { description => 'CT template, tar.xz', file => "$DEFAULT_STORAGE_DIR/template/cache/debian-10.0-standard_10.0-1_amd64.tar.xz", -- 2.47.3