ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/bin/treescan
Revision: 1.5
Committed: Sun Jan 9 05:10:28 2011 UTC (13 years, 4 months ago) by root
Branch: MAIN
CVS Tags: rel-3_93, rel-3_92, rel-3_91, rel-4_0, rel-3_9, rel-3_8
Changes since 1.4: +8 -1 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 root 1.3 our $VERSION = $IO::AIO::VERSION;
11 root 1.1
12 root 1.3 Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version");
13    
14 root 1.5 my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, $opt_nofiles, $opt_grep);
15 root 1.1
16     GetOptions
17     "quiet|q" => \$opt_silent,
18     "print0|0" => \$opt_print0,
19     "stat|s" => \$opt_stat,
20 root 1.3 "dirs|d" => \$opt_nofiles,
21     "files|f" => \$opt_nodirs,
22 root 1.5 "grep|g=s" => \$opt_grep,
23 root 1.3 or die "Usage: try $0 --help";
24 root 1.1
25     @ARGV = "." unless @ARGV;
26    
27 root 1.5 $opt_grep &&= qr{$opt_grep}s;
28    
29 root 1.1 sub printfn {
30 root 1.2 my ($prefix, $files, $suffix) = @_;
31 root 1.1
32 root 1.5 if ($opt_grep) {
33     @$files = grep "$prefix$_" =~ $opt_grep, @$files;
34     }
35    
36 root 1.1 if ($opt_print0) {
37 root 1.2 print map "$prefix$_$suffix\0", @$files;
38 root 1.1 } elsif (!$opt_silent) {
39 root 1.2 print map "$prefix$_$suffix\n", @$files;
40 root 1.1 }
41     }
42    
43     sub scan {
44     my ($path) = @_;
45    
46 root 1.2 $path .= "/";
47    
48     aioreq_pri -1;
49 root 1.1 aio_scandir $path, 8, sub {
50     my ($dirs, $files) = @_;
51    
52 root 1.3 printfn "", [$path] unless $opt_nodirs;
53     printfn $path, $files unless $opt_nofiles;
54 root 1.2
55 root 1.1 if ($opt_stat) {
56 root 1.2 aio_lstat "$path$_" for @$files;
57 root 1.1 }
58    
59 root 1.2 &scan ("$path$_") for @$dirs;
60 root 1.1 };
61     }
62    
63     IO::AIO::max_outstanding 64;
64     IO::AIO::min_parallel 32;
65    
66     for my $seed (@ARGV) {
67     $seed =~ s/\/+$//;
68     aio_lstat "$seed/.", sub {
69 root 1.4 if ($_[0]) {
70     print STDERR "$seed: $!\n";
71     } elsif (-d _) {
72 root 1.2 scan $seed;
73     } else {
74     printfn "", $seed, "/";
75     }
76 root 1.1 };
77     }
78    
79     IO::AIO::flush;
80