ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/bin/treescan
Revision: 1.2
Committed: Wed Apr 9 18:18:41 2008 UTC (16 years, 1 month ago) by root
Branch: MAIN
CVS Tags: rel-3_16, rel-3_19, rel-3_18, rel-3_2, rel-3_1, rel-3_17, rel-3_0, rel-3_15, rel-2_61, rel-3_03, rel-3_07, rel-2_62, rel-3_04, rel-3_01, rel-3_02, rel-3_06, rel-3_05
Changes since 1.1: +17 -11 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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 root 1.2 use strict;
7 root 1.1 use Getopt::Long;
8     use IO::AIO;
9    
10     Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order");
11    
12     my ($opt_silent, $opt_print0, $opt_stat);
13    
14     GetOptions
15     "quiet|q" => \$opt_silent,
16     "print0|0" => \$opt_print0,
17     "stat|s" => \$opt_stat,
18     ;
19    
20     @ARGV = "." unless @ARGV;
21    
22     sub printfn {
23 root 1.2 my ($prefix, $files, $suffix) = @_;
24 root 1.1
25     if ($opt_print0) {
26 root 1.2 print map "$prefix$_$suffix\0", @$files;
27 root 1.1 } elsif (!$opt_silent) {
28 root 1.2 print map "$prefix$_$suffix\n", @$files;
29 root 1.1 }
30     }
31    
32     sub scan {
33     my ($path) = @_;
34    
35 root 1.2 $path .= "/";
36    
37     aioreq_pri -1;
38 root 1.1 aio_scandir $path, 8, sub {
39     my ($dirs, $files) = @_;
40    
41 root 1.2 printfn "", [$path];
42     printfn $path, $files;
43    
44 root 1.1 if ($opt_stat) {
45 root 1.2 aio_lstat "$path$_" for @$files;
46 root 1.1 }
47    
48 root 1.2 &scan ("$path$_") for @$dirs;
49 root 1.1 };
50     }
51    
52     IO::AIO::max_outstanding 64;
53     IO::AIO::min_parallel 32;
54    
55     for my $seed (@ARGV) {
56     $seed =~ s/\/+$//;
57     aio_lstat "$seed/.", sub {
58 root 1.2 if (-d _) {
59     scan $seed;
60     } else {
61     printfn "", $seed, "/";
62     }
63 root 1.1 };
64     }
65    
66     IO::AIO::flush;
67