[vhffs-dev] [1964] autovivication of filehandle is deprecated (at least by me), using item by item readdir to save memory on large folder

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1964
Author:   gradator
Date:     2012-01-28 16:30:46 +0100 (Sat, 28 Jan 2012)
Log Message:
-----------
autovivication of filehandle is deprecated (at least by me), using item by item readdir to save memory on large folder

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Functions.pm

Modified: trunk/vhffs-api/src/Vhffs/Functions.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Functions.pm	2012-01-28 14:20:31 UTC (rev 1963)
+++ trunk/vhffs-api/src/Vhffs/Functions.pm	2012-01-28 15:30:46 UTC (rev 1964)
@@ -167,18 +167,15 @@
     my ($dir, $fmod, $dmod) = @_;
 
     my @files = ( $dir );
-    my $file;
-
-    while( $file = shift @files ) {
+    while( defined(my $file = shift @files) ) {
         if( -d $file ) {
             chmod( $dmod, $file );
-            opendir DIRECTORY, $file;
-            my @content = readdir( DIRECTORY );
-            closedir( DIRECTORY );
-            foreach my $item ( @content ) {
+            opendir( my $dh, $file );
+            while( defined(my $item = readdir($dh)) ) {
                 next if( $item eq '' or $item eq '..' or $item eq '.' );
                 push @files, $file.'/'.$item;
             }
+            closedir( $dh );
         }
         else {
             chmod( $fmod, $file );
@@ -194,18 +191,15 @@
     my $gid = shift;
 
     my @files = ($dir);
-    my $f;
-    
-    while( defined($f = shift @files) ) {
-        chown( $uid, $gid, $f );
-        if( -d $f ) {
-            opendir( DIRECTORY, $f );
-            my @content = readdir( DIRECTORY );
-            closedir( DIRECTORY );
-            foreach my $item ( @content ) {
+    while( defined(my $file = shift @files) ) {
+        chown( $uid, $gid, $file );
+        if( -d $file ) {
+            opendir( my $dh, $file );
+            while( defined(my $item = readdir($dh)) ) {
                 next if( $item eq '' or $item eq '..' or $item eq '.' );
-                push @files, $f.'/'.$item;
+                push @files, $file.'/'.$item;
             }
+            closedir( $dh );
         }
     }
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/