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