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.1 by root, Mon Sep 10 11:24:20 2007 UTC vs.
Revision 1.9 by root, Fri Sep 30 00:23:44 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines