/usr/share/doc/libio-aio-perl/examples/treescan is in libio-aio-perl 4.34-1build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #!/usr/bin/perl
# inspired by treescan by Jamie Lokier <jamie@imbolc.ucc.ie>
# about 40% faster than the original version (on my fs and raid :)
use common::sense;
use Getopt::Long;
use Time::HiRes ();
use IO::AIO;
our $VERSION = $IO::AIO::VERSION;
Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version");
my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs,
$opt_nofiles, $opt_grep, $opt_progress);
GetOptions
"quiet|q" => \$opt_silent,
"print0|0" => \$opt_print0,
"stat|s" => \$opt_stat,
"dirs|d" => \$opt_nofiles,
"files|f" => \$opt_nodirs,
"grep|g=s" => \$opt_grep,
"progress|p" => \$opt_progress,
or die "Usage: try $0 --help";
@ARGV = "." unless @ARGV;
$opt_grep &&= qr{$opt_grep}s;
my ($n_dirs, $n_files, $n_stats) = (0, 0, 0);
my ($n_last, $n_start) = (Time::HiRes::time) x 2;
sub printfn {
my ($prefix, $files, $suffix) = @_;
if ($opt_grep) {
@$files = grep "$prefix$_" =~ $opt_grep, @$files;
}
if ($opt_print0) {
print map "$prefix$_$suffix\0", @$files;
} elsif (!$opt_silent) {
print map "$prefix$_$suffix\n", @$files;
}
}
sub scan {
my ($path) = @_;
$path .= "/";
IO::AIO::poll_cb;
if ($opt_progress and $n_last + 1 < Time::HiRes::time) {
$n_last = Time::HiRes::time;
my $d = $n_last - $n_start;
printf STDERR "\r%d dirs (%g/s) %d files (%g/s) %d stats (%g/s) ",
$n_dirs, $n_dirs / $d,
$n_files, $n_files / $d,
$n_stats, $n_stats / $d
if $opt_progress;
}
aioreq_pri -1;
++$n_dirs;
aio_scandir $path, 8, sub {
my ($dirs, $files) = @_
or return warn "$path: $!\n";
printfn "", [$path] unless $opt_nodirs;
printfn $path, $files unless $opt_nofiles;
$n_files += @$files;
if ($opt_stat) {
aio_wd $path, sub {
my $wd = shift;
aio_lstat [$wd, $_] for @$files;
$n_stats += @$files;
};
}
&scan ("$path$_") for @$dirs;
};
}
IO::AIO::max_outstanding 100; # two fds per directory, so limit accordingly
IO::AIO::min_parallel 20;
for my $seed (@ARGV) {
$seed =~ s/\/+$//;
aio_lstat "$seed/.", sub {
if ($_[0]) {
print STDERR "$seed: $!\n";
} elsif (-d _) {
scan $seed;
} else {
printfn "", $seed, "/";
}
};
}
IO::AIO::flush;
|