--- IO-AIO/bin/treescan 2007/09/10 11:24:20 1.1 +++ IO-AIO/bin/treescan 2009/06/07 22:28:05 1.3 @@ -3,47 +3,53 @@ # 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; -Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order"); +our $VERSION = $IO::AIO::VERSION; -my ($opt_silent, $opt_print0, $opt_stat); +Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version"); + +my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, $opt_nofiles); GetOptions "quiet|q" => \$opt_silent, "print0|0" => \$opt_print0, "stat|s" => \$opt_stat, -; + "dirs|d" => \$opt_nofiles, + "files|f" => \$opt_nodirs, + or die "Usage: try $0 --help"; @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] unless $opt_nodirs; + printfn $path, $files unless $opt_nofiles; - for (@$dirs) { - printfn $path, $dirs, "/"; - &scan ("$path/$_") + if ($opt_stat) { + aio_lstat "$path$_" for @$files; } - printfn $path, $files; + &scan ("$path$_") for @$dirs; }; } @@ -53,7 +59,11 @@ for my $seed (@ARGV) { $seed =~ s/\/+$//; aio_lstat "$seed/.", sub { - scan $seed if -d _; + if (-d _) { + scan $seed; + } else { + printfn "", $seed, "/"; + } }; }