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 6E5D21FF0AA for ; Tue, 17 Nov 2026 21:40:43 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 263B6215A1; Tue, 17 Nov 2026 21:40:07 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v3 04/51] plugin: make get_subdir_files a proper subroutine and update style Date: Tue, 17 Nov 2026 21:38:36 +0100 Message-ID: <20261117203953.913035-5-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: 1794948001884 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.276 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: INEQWYV5E4K3C2W5UUIRW3RAQ4BAXFRN X-Message-ID-Hash: INEQWYV5E4K3C2W5UUIRW3RAQ4BAXFRN 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: This also renames a lot of variables so that they are in line with the rest of code and also a bit more readable, as follows: - $fn --> $filename - $notes_fn --> $notes_filename - $sid --> $storeid - $tt --> $vtype Signed-off-by: Max R. Carrara --- src/PVE/Storage/Plugin.pm | 68 +++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 7eb8a244..5f25ec51 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -1860,86 +1860,86 @@ sub list_images { } return $res; } -# list templates ($tt = ) -my $get_subdir_files = sub { - my ($sid, $path, $tt, $vmid) = @_; +# $vtype = +my sub get_subdir_files { + my ($storeid, $path, $vtype, $vmid) = @_; my $res = []; - foreach my $fn (<$path/*>) { + for my $filename (<$path/*>) { # A volume ID cannot represent a name with a newline, see parse_volume_id(). - next if $fn =~ m/\n/; + next if $filename =~ m/\n/; - my $st = File::stat::stat($fn); + my $st = File::stat::stat($filename); next if (!$st || S_ISDIR($st->mode)); my $info; - if ($tt eq 'iso') { - next if $fn !~ m!/([^/]+$PVE::Storage::ISO_EXT_RE_0)$!i; + if ($vtype eq 'iso') { + next if $filename !~ m!/([^/]+$PVE::Storage::ISO_EXT_RE_0)$!i; - $info = { volid => "$sid:iso/$1", format => 'iso' }; + $info = { volid => "$storeid:iso/$1", format => 'iso' }; - } elsif ($tt eq 'vztmpl') { - next if $fn !~ m!/([^/]+$PVE::Storage::VZTMPL_EXT_RE_1)$!; + } elsif ($vtype eq 'vztmpl') { + next if $filename !~ m!/([^/]+$PVE::Storage::VZTMPL_EXT_RE_1)$!; - $info = { volid => "$sid:vztmpl/$1", format => $2 eq 'tar' ? $2 : "t$2" }; + $info = { volid => "$storeid:vztmpl/$1", format => $2 eq 'tar' ? $2 : "t$2" }; - } elsif ($tt eq 'backup') { - next if $fn !~ m!/([^/]+$PVE::Storage::BACKUP_EXT_RE_2)$!; - my $original = $fn; + } elsif ($vtype eq 'backup') { + next if $filename !~ m!/([^/]+$PVE::Storage::BACKUP_EXT_RE_2)$!; + my $original = $filename; my $format = $2; - $fn = $1; + $filename = $1; # Attribute archives to a guest like parse_volname() does, which the access checks use. - next if defined($vmid) && $fn !~ m/^vzdump-(?:openvz|lxc|qemu)-\Q$vmid\E-/; + next if defined($vmid) && $filename !~ m/^vzdump-(?:openvz|lxc|qemu)-\Q$vmid\E-/; - $info = { volid => "$sid:backup/$fn", format => $format }; + $info = { volid => "$storeid:backup/$filename", format => $format }; - my $archive_info = eval { PVE::Storage::archive_info($fn) } // {}; + my $archive_info = eval { PVE::Storage::archive_info($filename) } // {}; $info->{ctime} = $archive_info->{ctime} if defined($archive_info->{ctime}); $info->{subtype} = $archive_info->{type} // 'unknown'; - if (defined($vmid) || $fn =~ m!\-([1-9][0-9]{2,8})\-[^/]+\.${format}$!) { + if (defined($vmid) || $filename =~ m!\-([1-9][0-9]{2,8})\-[^/]+\.${format}$!) { $info->{vmid} = $vmid // $1; } - my $notes_fn = $original . NOTES_EXT; - if (-f $notes_fn) { - my $notes = PVE::Tools::file_read_firstline($notes_fn); + my $notes_filename = $original . NOTES_EXT; + if (-f $notes_filename) { + my $notes = PVE::Tools::file_read_firstline($notes_filename); $info->{notes} = eval { decode('UTF-8', $notes, 1) } // $notes if defined($notes); } $info->{protected} = 1 if -e PVE::Storage::protection_file_path($original); - } elsif ($tt eq 'snippets') { + } elsif ($vtype eq 'snippets') { $info = { - volid => "$sid:snippets/" . basename($fn), + volid => "$storeid:snippets/" . basename($filename), format => 'snippet', }; - } elsif ($tt eq 'import') { + } elsif ($vtype eq 'import') { next - if $fn !~ + if $filename !~ m!/(${PVE::Storage::SAFE_CHAR_CLASS_RE}+$PVE::Storage::IMPORT_EXT_RE_1)$!i; - $info = { volid => "$sid:import/$1", format => "$2" }; + $info = { volid => "$storeid:import/$1", format => "$2" }; } $info->{size} = $st->size; $info->{ctime} //= $st->ctime; push @$res, $info; } return $res; -}; +} # If attributes are set on a volume, they should be included in the result. # See get_volume_attribute for a list of possible attributes. sub list_volumes { my ($class, $storeid, $scfg, $vmid, $content_types) = @_; @@ -1953,19 +1953,19 @@ sub list_volumes { $data = $class->list_images($storeid, $scfg, $vmid); } elsif ($scfg->{path}) { my $path = $class->get_subdir($scfg, $type); if ($type eq 'iso' && !defined($vmid)) { - $data = $get_subdir_files->($storeid, $path, 'iso'); + $data = get_subdir_files($storeid, $path, 'iso'); } elsif ($type eq 'vztmpl' && !defined($vmid)) { - $data = $get_subdir_files->($storeid, $path, 'vztmpl'); + $data = get_subdir_files($storeid, $path, 'vztmpl'); } elsif ($type eq 'backup') { - $data = $get_subdir_files->($storeid, $path, 'backup', $vmid); + $data = get_subdir_files($storeid, $path, 'backup', $vmid); } elsif ($type eq 'snippets') { - $data = $get_subdir_files->($storeid, $path, 'snippets'); + $data = get_subdir_files($storeid, $path, 'snippets'); } elsif ($type eq 'import') { - $data = $get_subdir_files->($storeid, $path, 'import'); + $data = get_subdir_files($storeid, $path, 'import'); } } next if !$data; -- 2.47.3