I've a maintenance script that uses File::Find::Rule (FFR) to traverse thousands of directories. Since I may need to stop the script in midstream I've incorporated sigtrap to set a variable that FFR can utilize.
The issue is this: I cannot find a way to truly stop FFR. I can use the variable in a rule that tells FFR to skip the remaining files (see the code below), but what if the signal arrives at file 1,000 and there are 10,000 more to go? It's not going to stop; it's going to skip 10,000 more files.
use strict; use warnings; use File::Find::Rule; use sigtrap 'handler' => \&abort, 'any'; ### So I can set up a kill command for testing. print $$, "\n"; <>; my $continue = 1; sub abort { print "Exiting...\n"; $continue = 0; } File::Find::Rule->exec(sub { return $continue }) ->directory ->exec( sub { print $_[2], "\n"; } ) ->in('/wherever');
I could use FFR's start/match combo to achieve this, but this has the side effect of arraying everything before the process even begins.
Have I missed something in the docs? Is there a way to achieve this without resorting to some homegrown opendir contraption?
Thanks!
In reply to Stopping File::Find::Rule by eff_i_g
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |