ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/bin/treescan
Revision: 1.8
Committed: Tue Sep 27 12:12:55 2011 UTC (12 years, 7 months ago) by root
Branch: MAIN
Changes since 1.7: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

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