--- IO-AIO/bin/treescan 2007/09/10 11:24:20 1.1 +++ IO-AIO/bin/treescan 2008/04/09 18:18:41 1.2 @@ -3,6 +3,7 @@ # inspired by treescan by Jamie Lokier # about 40% faster than the original version (on my fs and raid :) +use strict; use Getopt::Long; use IO::AIO; @@ -19,31 +20,32 @@ @ARGV = "." unless @ARGV; sub printfn { - my ($path, $files, $suffix) = @_; + my ($prefix, $files, $suffix) = @_; if ($opt_print0) { - print map "$path/$_$suffix\0", @$files; + print map "$prefix$_$suffix\0", @$files; } elsif (!$opt_silent) { - print map "$path/$_$suffix\n", @$files; + print map "$prefix$_$suffix\n", @$files; } } sub scan { my ($path) = @_; + $path .= "/"; + + aioreq_pri -1; aio_scandir $path, 8, sub { my ($dirs, $files) = @_; - if ($opt_stat) { - aio_stat "$path/$_" for @$files; - } + printfn "", [$path]; + printfn $path, $files; - for (@$dirs) { - printfn $path, $dirs, "/"; - &scan ("$path/$_") + if ($opt_stat) { + aio_lstat "$path$_" for @$files; } - printfn $path, $files; + &scan ("$path$_") for @$dirs; }; } @@ -53,7 +55,11 @@ for my $seed (@ARGV) { $seed =~ s/\/+$//; aio_lstat "$seed/.", sub { - scan $seed if -d _; + if (-d _) { + scan $seed; + } else { + printfn "", $seed, "/"; + } }; }