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 |
|
|
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 |
root |
1.2 |
my ($prefix, $files, $suffix) = @_; |
24 |
root |
1.1 |
|
25 |
|
|
if ($opt_print0) { |
26 |
root |
1.2 |
print map "$prefix$_$suffix\0", @$files; |
27 |
root |
1.1 |
} elsif (!$opt_silent) { |
28 |
root |
1.2 |
print map "$prefix$_$suffix\n", @$files; |
29 |
root |
1.1 |
} |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
sub scan { |
33 |
|
|
my ($path) = @_; |
34 |
|
|
|
35 |
root |
1.2 |
$path .= "/"; |
36 |
|
|
|
37 |
|
|
aioreq_pri -1; |
38 |
root |
1.1 |
aio_scandir $path, 8, sub { |
39 |
|
|
my ($dirs, $files) = @_; |
40 |
|
|
|
41 |
root |
1.2 |
printfn "", [$path]; |
42 |
|
|
printfn $path, $files; |
43 |
|
|
|
44 |
root |
1.1 |
if ($opt_stat) { |
45 |
root |
1.2 |
aio_lstat "$path$_" for @$files; |
46 |
root |
1.1 |
} |
47 |
|
|
|
48 |
root |
1.2 |
&scan ("$path$_") for @$dirs; |
49 |
root |
1.1 |
}; |
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 |
root |
1.2 |
if (-d _) { |
59 |
|
|
scan $seed; |
60 |
|
|
} else { |
61 |
|
|
printfn "", $seed, "/"; |
62 |
|
|
} |
63 |
root |
1.1 |
}; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
IO::AIO::flush; |
67 |
|
|
|