From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id A814E1FF0AB for ; Wed, 23 Sep 2026 17:07:02 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A514B21637; Wed, 23 Sep 2026 17:06:42 +0200 (CEST) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v2 05/50] plugin: make get_subdir_files a proper subroutine and update style Date: Wed, 23 Sep 2026 17:05:19 +0200 Message-ID: <20260923150606.531239-6-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260923150606.531239-1-m.carrara@proxmox.com> References: <20260923150606.531239-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: 1790175977261 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.478 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: BUQXU6RREXZIW4LH7EVLIF7N6LTWKSQD X-Message-ID-Hash: BUQXU6RREXZIW4LH7EVLIF7N6LTWKSQD 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: 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 | 66 +++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 6394b6e0..bd59c024 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -1695,69 +1695,69 @@ 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/*>) { - my $st = File::stat::stat($fn); + for my $filename (<$path/*>) { + 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; # only match for VMID now, to avoid false positives (VMID in parent directory name) - next if defined($vmid) && $fn !~ m/\S+-$vmid-\S+/; + next if defined($vmid) && $filename !~ m/\S+-$vmid-\S+/; - $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; @@ -1767,7 +1767,7 @@ my $get_subdir_files = sub { } 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. @@ -1785,15 +1785,15 @@ sub list_volumes { 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'); } } -- 2.47.3