ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/bin/treescan
(Generate patch)

Comparing IO-AIO/bin/treescan (file contents):
Revision 1.3 by root, Sun Jun 7 22:28:05 2009 UTC vs.
Revision 1.9 by root, Fri Sep 30 00:23:44 2011 UTC

9 9
10our $VERSION = $IO::AIO::VERSION; 10our $VERSION = $IO::AIO::VERSION;
11 11
12Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version"); 12Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version");
13 13
14my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, $opt_nofiles); 14my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, $opt_nofiles, $opt_grep);
15 15
16GetOptions 16GetOptions
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
26sub printfn { 29sub 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 }
36sub scan { 43sub scan {
37 my ($path) = @_; 44 my ($path) = @_;
38 45
39 $path .= "/"; 46 $path .= "/";
40 47
48 IO::AIO::poll_cb;
49
41 aioreq_pri -1; 50 aioreq_pri -1;
42 aio_scandir $path, 8, sub { 51 aio_scandir $path, 8, sub {
43 my ($dirs, $files) = @_; 52 my ($dirs, $files) = @_
53 or warn "$path: $!\n";
44 54
45 printfn "", [$path] unless $opt_nodirs; 55 printfn "", [$path] unless $opt_nodirs;
46 printfn $path, $files unless $opt_nofiles; 56 printfn $path, $files unless $opt_nofiles;
47 57
48 if ($opt_stat) { 58 if ($opt_stat) {
59 aio_wd $path, sub {
60 my $wd = shift;
61
49 aio_lstat "$path$_" for @$files; 62 aio_lstat [$wd, $_] for @$files;
63 };
50 } 64 }
51 65
52 &scan ("$path$_") for @$dirs; 66 &scan ("$path$_") for @$dirs;
53 }; 67 };
54} 68}
55 69
56IO::AIO::max_outstanding 64; 70IO::AIO::max_outstanding 100; # two fds per directory, so limit accordingly
57IO::AIO::min_parallel 32; 71IO::AIO::min_parallel 20;
58 72
59for my $seed (@ARGV) { 73for my $seed (@ARGV) {
60 $seed =~ s/\/+$//; 74 $seed =~ s/\/+$//;
61 aio_lstat "$seed/.", sub { 75 aio_lstat "$seed/.", sub {
76 if ($_[0]) {
77 print STDERR "$seed: $!\n";
62 if (-d _) { 78 } elsif (-d _) {
63 scan $seed; 79 scan $seed;
64 } else { 80 } else {
65 printfn "", $seed, "/"; 81 printfn "", $seed, "/";
66 } 82 }
67 }; 83 };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines