public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Noel Ullreich <n.ullreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-storage 1/2] update `list_volumes` to allow subdirs
Date: Fri,  3 Mar 2023 15:50:50 +0100	[thread overview]
Message-ID: <20230303145051.109925-2-n.ullreich@proxmox.com> (raw)
In-Reply-To: <20230303145051.109925-1-n.ullreich@proxmox.com>

iterate through subdirs to find all the isos/container
templates/snippets.

Signed-off-by: Noel Ullreich <n.ullreich@proxmox.com>
---
 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





  reply	other threads:[~2023-03-03 14:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-03 14:50 [pve-devel] [PATCH pve-storage 0/2] fix #623: show isos/tmplt/snippets in subdirs Noel Ullreich
2023-03-03 14:50 ` Noel Ullreich [this message]
2023-03-28 13:27   ` [pve-devel] [PATCH pve-storage 1/2] update `list_volumes` to allow subdirs Fabian Grünbichler
2023-03-03 14:50 ` [pve-devel] [PATCH pve-storage 2/2] change regex " Noel Ullreich
2023-03-28 13:27   ` Fabian Grünbichler
2023-03-29  7:21 ` [pve-devel] [PATCH pve-storage 0/2] fix #623: show isos/tmplt/snippets in subdirs Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230303145051.109925-2-n.ullreich@proxmox.com \
    --to=n.ullreich@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal