| 1 |
root |
1.1 |
#!/opt/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
# inspired by treescan by Jamie Lokier <jamie@imbolc.ucc.ie> |
| 4 |
|
|
# about 40% faster than the original version (on my fs and raid :) |
| 5 |
|
|
|
| 6 |
root |
1.2 |
use strict; |
| 7 |
root |
1.1 |
use Getopt::Long; |
| 8 |
|
|
use IO::AIO; |
| 9 |
|
|
|
| 10 |
root |
1.3 |
our $VERSION = $IO::AIO::VERSION; |
| 11 |
root |
1.1 |
|
| 12 |
root |
1.3 |
Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version"); |
| 13 |
|
|
|
| 14 |
|
|
my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, $opt_nofiles); |
| 15 |
root |
1.1 |
|
| 16 |
|
|
GetOptions |
| 17 |
|
|
"quiet|q" => \$opt_silent, |
| 18 |
|
|
"print0|0" => \$opt_print0, |
| 19 |
|
|
"stat|s" => \$opt_stat, |
| 20 |
root |
1.3 |
"dirs|d" => \$opt_nofiles, |
| 21 |
|
|
"files|f" => \$opt_nodirs, |
| 22 |
|
|
or die "Usage: try $0 --help"; |
| 23 |
root |
1.1 |
|
| 24 |
|
|
@ARGV = "." unless @ARGV; |
| 25 |
|
|
|
| 26 |
|
|
sub printfn { |
| 27 |
root |
1.2 |
my ($prefix, $files, $suffix) = @_; |
| 28 |
root |
1.1 |
|
| 29 |
|
|
if ($opt_print0) { |
| 30 |
root |
1.2 |
print map "$prefix$_$suffix\0", @$files; |
| 31 |
root |
1.1 |
} elsif (!$opt_silent) { |
| 32 |
root |
1.2 |
print map "$prefix$_$suffix\n", @$files; |
| 33 |
root |
1.1 |
} |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
|
sub scan { |
| 37 |
|
|
my ($path) = @_; |
| 38 |
|
|
|
| 39 |
root |
1.2 |
$path .= "/"; |
| 40 |
|
|
|
| 41 |
|
|
aioreq_pri -1; |
| 42 |
root |
1.1 |
aio_scandir $path, 8, sub { |
| 43 |
|
|
my ($dirs, $files) = @_; |
| 44 |
|
|
|
| 45 |
root |
1.3 |
printfn "", [$path] unless $opt_nodirs; |
| 46 |
|
|
printfn $path, $files unless $opt_nofiles; |
| 47 |
root |
1.2 |
|
| 48 |
root |
1.1 |
if ($opt_stat) { |
| 49 |
root |
1.2 |
aio_lstat "$path$_" for @$files; |
| 50 |
root |
1.1 |
} |
| 51 |
|
|
|
| 52 |
root |
1.2 |
&scan ("$path$_") for @$dirs; |
| 53 |
root |
1.1 |
}; |
| 54 |
|
|
} |
| 55 |
|
|
|
| 56 |
|
|
IO::AIO::max_outstanding 64; |
| 57 |
|
|
IO::AIO::min_parallel 32; |
| 58 |
|
|
|
| 59 |
|
|
for my $seed (@ARGV) { |
| 60 |
|
|
$seed =~ s/\/+$//; |
| 61 |
|
|
aio_lstat "$seed/.", sub { |
| 62 |
root |
1.2 |
if (-d _) { |
| 63 |
|
|
scan $seed; |
| 64 |
|
|
} else { |
| 65 |
|
|
printfn "", $seed, "/"; |
| 66 |
|
|
} |
| 67 |
root |
1.1 |
}; |
| 68 |
|
|
} |
| 69 |
|
|
|
| 70 |
|
|
IO::AIO::flush; |
| 71 |
|
|
|