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.2 by root, Wed Apr 9 18:18:41 2008 UTC vs.
Revision 1.9 by root, Fri Sep 30 00:23:44 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines