]> git.proxmox.com Git - pve-common.git/commitdiff
moved dir_glob_regex() and dir_glob_foreach() from PVE::Storage
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 28 Mar 2012 05:58:05 +0000 (07:58 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 28 Mar 2012 05:58:05 +0000 (07:58 +0200)
Makefile
data/PVE/Tools.pm
debian/changelog

index dd457b3bf17bdacab41ba335730c45379f02ec4f..19b28b5525f1d964da261e3f8c41e17298ee5ed7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 RELEASE=2.0
 
 VERSION=1.0
-PKGREL=22
+PKGREL=23
 
 PACKAGE=libpve-common-perl
 
index 12b5ba291045829eda74f9af967bb462dd188668..9ab82f5c5316c2d5b61cfec5a26ce328f22eb716 100644 (file)
@@ -7,6 +7,7 @@ use IO::Select;
 use File::Basename;
 use File::Path qw(make_path);
 use IO::File;
+use IO::Dir;
 use IPC::Open3;
 use Fcntl qw(:DEFAULT :flock);
 use base 'Exporter';
@@ -22,6 +23,8 @@ run_command
 file_set_contents 
 file_get_contents
 file_read_firstline
+dir_glob_regex
+dir_glob_foreach
 split_list
 template_replace
 safe_print
@@ -826,4 +829,34 @@ sub dump_logfile {
     return ($count, $lines);
 }
 
+sub dir_glob_regex {
+    my ($dir, $regex) = @_;
+
+    my $dh = IO::Dir->new ($dir);
+    return wantarray ? () : undef if !$dh;
+  
+    while (defined(my $tmp = $dh->read)) { 
+       if (my @res = $tmp =~ m/^($regex)$/) {
+           $dh->close;
+           return wantarray ? @res : $tmp;
+       }
+    }
+    $dh->close;
+
+    return wantarray ? () : undef;
+}
+
+sub dir_glob_foreach {
+    my ($dir, $regex, $func) = @_;
+
+    my $dh = IO::Dir->new ($dir);
+    if (defined $dh) {
+       while (defined(my $tmp = $dh->read)) {
+           if (my @res = $tmp =~ m/^($regex)$/) {
+               &$func (@res);
+           }
+       }
+    } 
+}
+
 1;
index 85277a4f42f6a1c8c667ec10f110d0d7d1c2e573..345e934ad0f57435ef387fd5d6c8033c433afc51 100644 (file)
@@ -1,3 +1,10 @@
+libpve-common-perl (1.0-23) unstable; urgency=low
+
+  * moved dir_glob_regex() and dir_glob_foreach() from PVE::Storage 
+  to PVE::Tools
+  
+ -- Proxmox Support Team <support@proxmox.com>  Wed, 28 Mar 2012 07:56:49 +0200
+
 libpve-common-perl (1.0-22) unstable; urgency=low
 
   * return number of sockets in read_cpuinfo