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 35EAE1FF0AA for ; Tue, 17 Nov 2026 21:46:48 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id F3942219FE; Tue, 17 Nov 2026 21:43:58 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v3 43/51] plugin: list content directories without globbing Date: Tue, 17 Nov 2026 21:39:15 +0100 Message-ID: <20261117203953.913035-44-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: 1794948083768 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.240 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: QHCZH26P5BLKERKTICI2G6S5WVUM4UPV X-Message-ID-Hash: QHCZH26P5BLKERKTICI2G6S5WVUM4UPV 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: Files of the iso, vztmpl, backup, snippets and import content types were found by globbing the content directory with `<$dir/*>`. Perl's glob splits its pattern on whitespace and expands braces and the tilde in it, so for a storage path containing such characters the listing silently came up empty. Only the listing of these content types changes. VM and container images are still found by globbing in list_images(), so storage paths containing such characters remain unsupported for them. Read the directory entries with readdir instead, skipping hidden entries and sorting them like the glob did, so the result is otherwise unchanged. This also prepares for scanning nested subdirectories, whose names may contain whitespace as well. Signed-off-by: Max R. Carrara --- src/PVE/Storage/Plugin.pm | 14 +++++++++++++- src/test/list_volumes_test.pm | 31 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 73e43cea..b8f415a8 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -1868,10 +1868,22 @@ sub list_images { } return $res; } +# Returns the paths of all non-hidden entries in $dir, sorted like a `<$dir/*>` glob would. Unlike +# such a glob, this does not split $dir on whitespace or expand any glob metacharacters in it. +my sub list_dir_entries { + my ($dir) = @_; + + opendir(my $dh, $dir) or return (); + my @names = grep { !m/^\./ } readdir($dh); + closedir($dh); + + return map { "$dir/$_" } sort { lc($a) cmp lc($b) || $a cmp $b } @names; +} + # $vtype = my sub get_subdir_files { my ($class, $storeid, $scfg, $vtype, $vmid) = @_; # FIXME: Call plugin_get_vtype_subdir() instead of $class->get_subdir() @@ -1958,11 +1970,11 @@ my sub get_subdir_files { } return; }; - for my $path (<$vtype_subdir/*>) { + for my $path (list_dir_entries($vtype_subdir)) { my $st = File::stat::stat($path); # A volume ID cannot represent a name with a newline, see parse_volume_id(). next if $path =~ m/\n/; diff --git a/src/test/list_volumes_test.pm b/src/test/list_volumes_test.pm index 76831de9..4932dbbf 100644 --- a/src/test/list_volumes_test.pm +++ b/src/test/list_volumes_test.pm @@ -75,10 +75,12 @@ my $DEFAULT_SCFG = { backup => 1, import => 1, }, }; +my $SPECIAL_CHARS_STORAGE_PATH = "$DEFAULT_STORAGE_PATH/path with {glob} chars"; + my @BACKING_FILE_SUFFIXES = ('qcow2', 'raw', 'vmdk', 'vhdx'); =head2 TEST CASE FORMAT The parameters for individual test cases are hashes with the following @@ -1349,10 +1351,39 @@ my $test_param_list = [ file => "$DEFAULT_STORAGE_PATH/import/import.ova", expected => undef, }, ], }, + { + description => 'Storage path containing whitespace and glob metacharacters', + storeid => $DEFAULT_STOREID, + scfg => { $DEFAULT_SCFG->%*, path => $SPECIAL_CHARS_STORAGE_PATH }, + vmid => undef, + vtypes => ['iso', 'snippets'], + cases => [ + { + file => "$SPECIAL_CHARS_STORAGE_PATH/template/iso/debian.iso", + expected => { + content => 'iso', + ctime => $DEFAULT_CTIME, + format => 'iso', + size => $DEFAULT_SIZE, + volid => 'local:iso/debian.iso', + }, + }, + { + file => "$SPECIAL_CHARS_STORAGE_PATH/snippets/userconfig.yaml", + expected => { + content => 'snippets', + ctime => $DEFAULT_CTIME, + format => 'snippet', + size => $DEFAULT_SIZE, + volid => 'local:snippets/userconfig.yaml', + }, + }, + ], + }, ]; # Additional test cases that cannot be constructed within the list above { my $file_name = "vzdump-qemu-16110-2020_03_30-21_13_55.vma"; -- 2.47.3