From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 245C38452 for ; Fri, 3 Mar 2023 15:50:59 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0D6CE1902B for ; Fri, 3 Mar 2023 15:50:59 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 3 Mar 2023 15:50:57 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 92DFC461DD for ; Fri, 3 Mar 2023 15:50:55 +0100 (CET) From: Noel Ullreich To: pve-devel@lists.proxmox.com Date: Fri, 3 Mar 2023 15:50:50 +0100 Message-Id: <20230303145051.109925-2-n.ullreich@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230303145051.109925-1-n.ullreich@proxmox.com> References: <20230303145051.109925-1-n.ullreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.100 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 Subject: [pve-devel] [PATCH pve-storage 1/2] update `list_volumes` to allow subdirs X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Mar 2023 14:50:59 -0000 iterate through subdirs to find all the isos/container templates/snippets. Signed-off-by: Noel Ullreich --- PVE/Storage/Plugin.pm | 65 ++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm index ca7a0d4..bf1d564 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -9,6 +9,7 @@ use File::chdir; use File::Path; use File::Basename; use File::stat qw(); +use File::Find; use PVE::Tools qw(run_command); use PVE::JSONSchema qw(get_standard_option register_standard_option); @@ -1275,46 +1276,66 @@ sub list_volumes { my $vmlist = PVE::Cluster::get_vmlist(); foreach my $type (@$content_types) { my $data; + my @list_of_dirs; if ($type eq 'images' || $type eq 'rootdir') { $data = $class->list_images($storeid, $scfg, $vmid); + push (@list_of_dirs, $data) if $data; #fix this } elsif ($scfg->{path}) { my $path = $class->get_subdir($scfg, $type); + my @subdirs; + my $wanted = sub { + my ($dev,$ino,$mode,$nlink,$uid,$gid); + + (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && + -d _ + && push(@subdirs, $File::Find::name); + }; + File::Find::find({wanted => $wanted, untaint => 1}, $path); if ($type eq 'iso' && !defined($vmid)) { - $data = $get_subdir_files->($storeid, $path, 'iso'); + for (@subdirs) { + $data = $get_subdir_files->($storeid, $_, 'iso',); + push @list_of_dirs, $data; + } } elsif ($type eq 'vztmpl'&& !defined($vmid)) { - $data = $get_subdir_files->($storeid, $path, 'vztmpl'); + for (@subdirs) { + $data = $get_subdir_files->($storeid, $_, 'vztmpl'); + push @list_of_dirs, $data; + } } elsif ($type eq 'backup') { $data = $get_subdir_files->($storeid, $path, 'backup', $vmid); + push(@list_of_dirs, $data) if $data; } elsif ($type eq 'snippets') { - $data = $get_subdir_files->($storeid, $path, 'snippets'); + for (@subdirs){ + $data = $get_subdir_files->($storeid, $_, 'snippets'); + push(@list_of_dirs, $data) if $data; + } } } - - next if !$data; - - foreach my $item (@$data) { - if ($type eq 'images' || $type eq 'rootdir') { - my $vminfo = $vmlist->{ids}->{$item->{vmid}}; - my $vmtype; - if (defined($vminfo)) { - $vmtype = $vminfo->{type}; - } - if (defined($vmtype) && $vmtype eq 'lxc') { - $item->{content} = 'rootdir'; + next if !@list_of_dirs; #if list of dirs is empty, there is no data either + + for (@list_of_dirs) { + foreach my $item (@$_) { + if ($type eq 'images' || $type eq 'rootdir') { + my $vminfo = $vmlist->{ids}->{$item->{vmid}}; + my $vmtype; + if (defined($vminfo)) { + $vmtype = $vminfo->{type}; + } + if (defined($vmtype) && $vmtype eq 'lxc') { + $item->{content} = 'rootdir'; + } else { + $item->{content} = 'images'; + } + next if $type ne $item->{content}; } else { - $item->{content} = 'images'; + $item->{content} = $type; } - next if $type ne $item->{content}; - } else { - $item->{content} = $type; + push @$res, $item; } - - push @$res, $item; } } - return $res; } -- 2.30.2