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 |
Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order"); |
11 |
|
12 |
my ($opt_silent, $opt_print0, $opt_stat); |
13 |
|
14 |
GetOptions |
15 |
"quiet|q" => \$opt_silent, |
16 |
"print0|0" => \$opt_print0, |
17 |
"stat|s" => \$opt_stat, |
18 |
; |
19 |
|
20 |
@ARGV = "." unless @ARGV; |
21 |
|
22 |
sub printfn { |
23 |
my ($prefix, $files, $suffix) = @_; |
24 |
|
25 |
if ($opt_print0) { |
26 |
print map "$prefix$_$suffix\0", @$files; |
27 |
} elsif (!$opt_silent) { |
28 |
print map "$prefix$_$suffix\n", @$files; |
29 |
} |
30 |
} |
31 |
|
32 |
sub scan { |
33 |
my ($path) = @_; |
34 |
|
35 |
$path .= "/"; |
36 |
|
37 |
aioreq_pri -1; |
38 |
aio_scandir $path, 8, sub { |
39 |
my ($dirs, $files) = @_; |
40 |
|
41 |
printfn "", [$path]; |
42 |
printfn $path, $files; |
43 |
|
44 |
if ($opt_stat) { |
45 |
aio_lstat "$path$_" for @$files; |
46 |
} |
47 |
|
48 |
&scan ("$path$_") for @$dirs; |
49 |
}; |
50 |
} |
51 |
|
52 |
IO::AIO::max_outstanding 64; |
53 |
IO::AIO::min_parallel 32; |
54 |
|
55 |
for my $seed (@ARGV) { |
56 |
$seed =~ s/\/+$//; |
57 |
aio_lstat "$seed/.", sub { |
58 |
if (-d _) { |
59 |
scan $seed; |
60 |
} else { |
61 |
printfn "", $seed, "/"; |
62 |
} |
63 |
}; |
64 |
} |
65 |
|
66 |
IO::AIO::flush; |
67 |
|