Changeset 1370 for trunk


Ignore:
Timestamp:
Dec 6, 2009, 11:08:35 PM (15 years ago)
Author:
dwilson
Message:
trac #70 - parallel-find enhancement
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/locker/sbin/parallel-find.pl

    r1285 r1370  
    22
    33# Script to help generate find the .scripts-version files
     4
     5use LockFile::Simple qw(trylock unlock);
    46
    57use lib '/mit/scripts/sec-tools/perl';
     
    79open(FILE, "</mit/scripts/sec-tools/store/scriptslist");
    810my $dump = "/mit/scripts/sec-tools/store/versions";
     11my $dumpbackup = "/mit/scripts/sec-tools/store/versions-backup";
    912
    10 (! -e $dump) || die "Output directory exists: $dump";
    11 system("mkdir", $dump) && die;
     13# try to grab a lock on the version directory
     14trylock($dump) || die "Can't acquire lock on $dump .  Another parallel-find may be running.  If you are SURE there is not, remove the lock file and retry.";
     15
     16sub unlock_and_die ($) {
     17    my $msg = shift;
     18    unlock($dump);
     19    die $msg;
     20}
     21
     22# if the versions directory exists, move it to versions-backup
     23# (removing the backup directory if necessary).  Then make a new copy.
     24if (-e $dump){
     25    if (-e $dumpbackup){
     26        system("rm -rf $dumpbackup") && unlock_and_die "Can't remove old backup directory $dumpbackup";
     27    }
     28    system("mv", $dump, $dumpbackup) && unlock_and_die "Unable to back up current directory $dump";
     29}
     30system("mkdir", $dump) && unlock_and_die;
    1231
    1332use Proc::Queue size => 40, debug => 0, trace => 0;
     
    7897    1 while waitpid(-1, WNOHANG)>0; # avoids memory leaks in Proc::Queue
    7998}
     99
     100unlock($dump);
     1011;
Note: See TracChangeset for help on using the changeset viewer.