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.17 by root, Sun Nov 13 16:19:31 2016 UTC vs.
Revision 1.21 by root, Wed Dec 30 07:45:33 2020 UTC

16 -s, --stat call stat on every entry, to get stat data into cache 16 -s, --stat call stat on every entry, to get stat data into cache
17 -d, --dirs only list dirs 17 -d, --dirs only list dirs
18 -f, --files only list files 18 -f, --files only list files
19 -p, --progress regularly print progress to stderr 19 -p, --progress regularly print progress to stderr
20 --sync open/fsync/close every entry 20 --sync open/fsync/close every entry
21 -g, --grep=RE only list files that match the gibven perl RegEx 21 -g, --grep=RE only list files that match the given perl RegEx
22 22
23=head1 DESCRIPTION 23=head1 DESCRIPTION
24 24
25The F<treescan> command scans directories and their contents 25The F<treescan> command scans directories and their contents
26recursively. By default it lists all files and directories (with trailing 26recursively. By default it lists all files and directories (with trailing
50 50
51Normally, F<treescan> will use heuristics to avoid most C<stat> calls, 51Normally, F<treescan> will use heuristics to avoid most C<stat> calls,
52which is what makes it so fast. This option forces it to C<stat> every file. 52which is what makes it so fast. This option forces it to C<stat> every file.
53 53
54This is only useful for the side effect of pulling the C<stat> data into 54This is only useful for the side effect of pulling the C<stat> data into
55the cache. If your disk cache is big enough, it will be filled with file 55the cache. If your disk cache is big enough, it will be filled with
56metadata after F<treescan> is done, which can speed up subsequent commands 56file meta data after F<treescan> is done, which can speed up subsequent
57considerably. Often, you can run F<treescan> in parallel with other 57commands considerably. Often, you can run F<treescan> in parallel with
58directory-scanning programs to speed them up. 58other directory-scanning programs to speed them up.
59 59
60=item -d, --dirs 60=item -d, --dirs
61 61
62Only lists directories, not file paths. This is useful if you quickly want 62Only lists directories, not file paths. This is useful if you quickly want
63a list of directories and their subdirectories. 63a list of directories and their subdirectories.
64 64
65=item -f, --files 65=item -f, --files
66 66
67Only list files, not directories. This is useful if you want to coperate 67Only list files, not directories. This is useful if you want to operate on
68on all files in a hierarchy, and the directories would ony get in the way. 68all files in a hierarchy, and the directories would ony get in the way.
69 69
70=item -p, --progress 70=item -p, --progress
71 71
72Regularly print some progress information to standard error. This is 72Regularly print some progress information to standard error. This is
73useful to get some progress information on long running tasks. Since 73useful to get some progress information on long running tasks. Since
131 ); 131 );
132} 132}
133 133
134@ARGV = "." unless @ARGV; 134@ARGV = "." unless @ARGV;
135 135
136my @todo; # list of dirs/files still left to scan
137
136$opt_grep &&= qr{$opt_grep}s; 138$opt_grep &&= qr{$opt_grep}s;
137 139
138my ($n_dirs, $n_files, $n_stats) = (0, 0, 0); 140my ($n_dirs, $n_files, $n_stats) = (0, 0, 0);
139my ($n_last, $n_start) = (Time::HiRes::time) x 2; 141my ($n_last, $n_start) = (Time::HiRes::time) x 2;
140 142
195 aio_pathsync [$wd, $_] for @$files; 197 aio_pathsync [$wd, $_] for @$files;
196 aio_pathsync $wd; 198 aio_pathsync $wd;
197 }; 199 };
198 } 200 }
199 201
200 &scan ("$path$_") for @$dirs; 202 push @todo, "$path$_"
203 for sort { $b cmp $a } @$dirs;
201 }; 204 };
202} 205}
203 206
204IO::AIO::max_outstanding 100; # two fds per directory, so limit accordingly 207IO::AIO::max_outstanding 100; # two fds per directory, so limit accordingly
205IO::AIO::min_parallel 20; 208IO::AIO::min_parallel 20;
206 209
207for my $seed (@ARGV) { 210@todo = reverse @ARGV;
211
212while () {
213 if (@todo) {
214 my $seed = pop @todo;
208 $seed =~ s/\/+$//; 215 $seed =~ s/\/+$//;
209 aio_lstat "$seed/.", sub { 216 aio_lstat "$seed/.", sub {
210 if ($_[0]) { 217 if ($_[0]) {
211 print STDERR "$seed: $!\n"; 218 print STDERR "$seed: $!\n";
212 } elsif (-d _) { 219 } elsif (-d _) {
213 scan $seed; 220 scan $seed;
214 } else { 221 } else {
215 printfn "", $seed, "/"; 222 printfn "", $seed, "/";
223 }
216 } 224 };
225 } else {
226 IO::AIO::poll_wait;
217 }; 227 }
218}
219 228
220IO::AIO::flush; 229 last unless IO::AIO::nreqs;
221 230
231 IO::AIO::poll_cb;
232}
233

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines