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