[PATCH pve-storage v1 52/54] test: add tests guarding against subdir scanning for vtypes

Max R. Carrara
2026-04-22T11:20:06Z

Add tests that guard against implementing nested subdirectory scanning
for the 'backup' volume type in `parser_tests.pl`, and for the
'images' and 'backup' volume types in `path_to_volume_id_test.pm`.

For the 'backup' vtype, also add a comment above the parser's
corresponding regex that we do not allow nested subdirs there.

This is done mainly to prevent implementing subdir scanning blindly in
the future for these two volume types.

While adding support for subdir scanning for the 'backup' volume type
would probably be fairly trivial, there is also no (known) need for it
currently.

For the 'images' type, there currently is no plan or need to support
subdir scanning, and it would probably not make much sense anyway.

Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
---
src/PVE/Storage/Common/Parse.pm | 1 +
src/PVE/Storage/Common/test/parser_tests.pl | 40 +++++++++++++++++++++
src/test/path_to_volume_id_test.pm | 11 ++++++
3 files changed, 52 insertions(+)

diff --git a/src/PVE/Storage/Common/Parse.pm b/src/PVE/Storage/Common/Parse.pm
index 6bab7e28..b33fe78e 100644
--- a/src/PVE/Storage/Common/Parse.pm
+++ b/src/PVE/Storage/Common/Parse.pm
@@ -103,6 +103,7 @@ my $RE_GUEST_VZDUMP_BACKUP_FILE_NAME = qr!
- [^/]+
!xn;

+# NOTE: Not supporting subdirectories here.
my $RE_BACKUP_FILE_PATH = qr!
(?<path>
(?<file>
diff --git a/src/PVE/Storage/Common/test/parser_tests.pl b/src/PVE/Storage/Common/test/parser_tests.pl
index a788f2ab..882c0675 100755
--- a/src/PVE/Storage/Common/test/parser_tests.pl
+++ b/src/PVE/Storage/Common/test/parser_tests.pl
@@ -474,6 +474,46 @@ my $volname_cases_backup_invalid = [
},
expected => undef,
},
+ {
+ description => "Subdirectory (backup)",
+ args => {
+ path => 'subdir/vzdump-qemu-16110-2020_03_30-21_12_40.tar.gz',
+ vtype => 'backup',
+ },
+ expected => undef,
+ },
+ {
+ description => "Nested subdirectory (backup)",
+ args => {
+ path => 'deeply/nested/subdir/vzdump-qemu-16110-2020_03_30-21_12_40.tar.gz',
+ vtype => 'backup',
+ },
+ expected => undef,
+ },
+ {
+ description => "Parent dir reference in path (beginning) (backup)",
+ args => {
+ path => '../vzdump-lxc-16112-2020_03_30-21_49_30.tar.gz',
+ vtype => 'backup',
+ },
+ expected => undef,
+ },
+ {
+ description => "Parent dir reference in path (middle) (backup)",
+ args => {
+ path => 'subdir/../vzdump-lxc-16112-2020_03_30-21_49_30.tar.gz',
+ vtype => 'backup',
+ },
+ expected => undef,
+ },
+ {
+ description => "Parent dir reference in path (end) (backup)",
+ args => {
+ path => 'subdir/vzdump-lxc-16112-2020_03_30-21_49_30.tar.gz/..',
+ vtype => 'backup',
+ },
+ expected => undef,
+ },
];

my $volname_cases_snippets_valid = [
diff --git a/src/test/path_to_volume_id_test.pm b/src/test/path_to_volume_id_test.pm
index 3bfb37a6..2eb17e9e 100644
--- a/src/test/path_to_volume_id_test.pm
+++ b/src/test/path_to_volume_id_test.pm
@@ -246,11 +246,22 @@ my $tests = [
file => "$DEFAULT_STORAGE_DIR/dump/vzdump-qemu-16110-2020_03_30-21_12_40.vms.gz",
expected => [''],
},
+ {
+ description => 'Backup, nested subdirectories, vma.gz',
+ file =>
+ "$DEFAULT_STORAGE_DIR/dump/foo/bar/baz/vzdump-qemu-16110-2020_03_30-21_11_40.vma.gz",
+ expected => [''],
+ },
{
description => 'Image, string as vmid in folder name',
file => "$DEFAULT_STORAGE_DIR/images/ssss/vm-1234-disk-0.qcow2",
expected => [''],
},
+ {
+ description => 'Image, additional nested subdirectories before vmid',
+ file => "$DEFAULT_STORAGE_DIR/images/foo/bar/baz/1234/vm-1234-disk-0.qcow2",
+ expected => [''],
+ },
{
description => 'Import, non ova/ovf/disk image in import dir',
file => "$DEFAULT_STORAGE_DIR/import/test.foo",
--
2.47.3