… | |
… | |
9 | |
9 | |
10 | our $VERSION = $IO::AIO::VERSION; |
10 | our $VERSION = $IO::AIO::VERSION; |
11 | |
11 | |
12 | Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version"); |
12 | Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version"); |
13 | |
13 | |
14 | my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, $opt_nofiles); |
14 | my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, $opt_nofiles, $opt_grep); |
15 | |
15 | |
16 | GetOptions |
16 | GetOptions |
17 | "quiet|q" => \$opt_silent, |
17 | "quiet|q" => \$opt_silent, |
18 | "print0|0" => \$opt_print0, |
18 | "print0|0" => \$opt_print0, |
19 | "stat|s" => \$opt_stat, |
19 | "stat|s" => \$opt_stat, |
20 | "dirs|d" => \$opt_nofiles, |
20 | "dirs|d" => \$opt_nofiles, |
21 | "files|f" => \$opt_nodirs, |
21 | "files|f" => \$opt_nodirs, |
|
|
22 | "grep|g=s" => \$opt_grep, |
22 | or die "Usage: try $0 --help"; |
23 | or die "Usage: try $0 --help"; |
23 | |
24 | |
24 | @ARGV = "." unless @ARGV; |
25 | @ARGV = "." unless @ARGV; |
25 | |
26 | |
|
|
27 | $opt_grep &&= qr{$opt_grep}s; |
|
|
28 | |
26 | sub printfn { |
29 | sub printfn { |
27 | my ($prefix, $files, $suffix) = @_; |
30 | my ($prefix, $files, $suffix) = @_; |
28 | |
31 | |
|
|
32 | if ($opt_grep) { |
|
|
33 | @$files = grep "$prefix$_" =~ $opt_grep, @$files; |
|
|
34 | } |
|
|
35 | |
29 | if ($opt_print0) { |
36 | if ($opt_print0) { |
30 | print map "$prefix$_$suffix\0", @$files; |
37 | print map "$prefix$_$suffix\0", @$files; |
31 | } elsif (!$opt_silent) { |
38 | } elsif (!$opt_silent) { |
32 | print map "$prefix$_$suffix\n", @$files; |
39 | print map "$prefix$_$suffix\n", @$files; |
33 | } |
40 | } |
… | |
… | |
43 | my ($dirs, $files) = @_; |
50 | my ($dirs, $files) = @_; |
44 | |
51 | |
45 | printfn "", [$path] unless $opt_nodirs; |
52 | printfn "", [$path] unless $opt_nodirs; |
46 | printfn $path, $files unless $opt_nofiles; |
53 | printfn $path, $files unless $opt_nofiles; |
47 | |
54 | |
|
|
55 | IO::AIO::poll_cb; |
|
|
56 | |
48 | if ($opt_stat) { |
57 | if ($opt_stat) { |
|
|
58 | aio_wd $path, sub { |
|
|
59 | my $wd = shift; |
|
|
60 | |
49 | aio_lstat "$path$_" for @$files; |
61 | aio_lstat [$wd, $_] for @$files; |
|
|
62 | }; |
50 | } |
63 | } |
51 | |
64 | |
52 | &scan ("$path$_") for @$dirs; |
65 | &scan ("$path$_") for @$dirs; |
53 | }; |
66 | }; |
54 | } |
67 | } |
55 | |
68 | |
56 | IO::AIO::max_outstanding 64; |
69 | IO::AIO::max_outstanding 400; # two fds per directory, so limit accordingly |
57 | IO::AIO::min_parallel 32; |
70 | IO::AIO::min_parallel 20; |
58 | |
71 | |
59 | for my $seed (@ARGV) { |
72 | for my $seed (@ARGV) { |
60 | $seed =~ s/\/+$//; |
73 | $seed =~ s/\/+$//; |
61 | aio_lstat "$seed/.", sub { |
74 | aio_lstat "$seed/.", sub { |
62 | if ($_[0]) { |
75 | if ($_[0]) { |