From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id D4ED91FF13B for ; Wed, 22 Apr 2026 13:13:50 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D3CE4167F2; Wed, 22 Apr 2026 13:13:43 +0200 (CEST) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v1 05/54] plugin: make get_subdir_files a proper subroutine and update style Date: Wed, 22 Apr 2026 13:12:31 +0200 Message-ID: <20260422111322.257380-6-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260422111322.257380-1-m.carrara@proxmox.com> References: <20260422111322.257380-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: 1776856320223 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.086 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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: AI7DLOHI2YSYI4E2V4USFBR7AJY3Z3DK X-Message-ID-Hash: AI7DLOHI2YSYI4E2V4USFBR7AJY3Z3DK 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 84ac412a..07233db3 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -1669,69 +1669,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; @@ -1741,7 +1741,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. @@ -1759,15 +1759,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