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 |
use strict; |
7 |
use Getopt::Long; |
8 |
use IO::AIO; |
9 |
|
10 |
our $VERSION = $IO::AIO::VERSION; |
11 |
|
12 |
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 |
|
16 |
GetOptions |
17 |
"quiet|q" => \$opt_silent, |
18 |
"print0|0" => \$opt_print0, |
19 |
"stat|s" => \$opt_stat, |
20 |
"dirs|d" => \$opt_nofiles, |
21 |
"files|f" => \$opt_nodirs, |
22 |
or die "Usage: try $0 --help"; |
23 |
|
24 |
@ARGV = "." unless @ARGV; |
25 |
|
26 |
sub printfn { |
27 |
my ($prefix, $files, $suffix) = @_; |
28 |
|
29 |
if ($opt_print0) { |
30 |
print map "$prefix$_$suffix\0", @$files; |
31 |
} elsif (!$opt_silent) { |
32 |
print map "$prefix$_$suffix\n", @$files; |
33 |
} |
34 |
} |
35 |
|
36 |
sub scan { |
37 |
my ($path) = @_; |
38 |
|
39 |
$path .= "/"; |
40 |
|
41 |
aioreq_pri -1; |
42 |
aio_scandir $path, 8, sub { |
43 |
my ($dirs, $files) = @_; |
44 |
|
45 |
printfn "", [$path] unless $opt_nodirs; |
46 |
printfn $path, $files unless $opt_nofiles; |
47 |
|
48 |
if ($opt_stat) { |
49 |
aio_lstat "$path$_" for @$files; |
50 |
} |
51 |
|
52 |
&scan ("$path$_") for @$dirs; |
53 |
}; |
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 |
if (-d _) { |
63 |
scan $seed; |
64 |
} else { |
65 |
printfn "", $seed, "/"; |
66 |
} |
67 |
}; |
68 |
} |
69 |
|
70 |
IO::AIO::flush; |
71 |
|