From 911ede9b12999cee8653ebe02c4dc15ad8d1dc86 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 14 Jan 2017 14:26:33 +0100 Subject: [PATCH] new helper add_dirs (copied from pveproxy.pm) --- PVE/APIServer/AnyEvent.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/PVE/APIServer/AnyEvent.pm b/PVE/APIServer/AnyEvent.pm index 7e75aa8..101c5dc 100755 --- a/PVE/APIServer/AnyEvent.pm +++ b/PVE/APIServer/AnyEvent.pm @@ -8,6 +8,7 @@ use POSIX qw(strftime EINTR EAGAIN); use Fcntl; use IO::File; use File::stat qw(); +use File::Find; use MIME::Base64; use Digest::MD5; use Digest::SHA; @@ -1577,6 +1578,7 @@ sub new { $self->{cookie_name} //= 'PVEAuthCookie'; $self->{base_uri} //= "/api2"; + $self->{dirs} //= {}; # init inotify PVE::INotify::inotify_init(); @@ -1649,6 +1651,24 @@ sub new { return $self; } +# static helper to add directory including all subdirs +# This can be used to setup $self->{dirs} +sub add_dirs { + my ($result_hash, $alias, $subdir) = @_; + + $result_hash->{$alias} = $subdir; + + my $wanted = sub { + my $dir = $File::Find::dir; + if ($dir =~m!^$subdir(.*)$!) { + my $name = "$alias$1/"; + $result_hash->{$name} = "$dir/"; + } + }; + + find({wanted => $wanted, follow => 0, no_chdir => 1}, $subdir); +} + # abstract functions - subclass should overwrite/implement them sub verify_spice_connect_url {