2 # $Id: expire.in,v 1.4 1999/09/16 07:16:47 gecko Exp $
4 # Load modules and set envirnment
5 require('/etc/debbugs/config');
6 require('/usr/lib/debbugs/errorlib');
8 $ENV{'PATH'}= '/usr/lib/debbugs'.$ENV{'PATH'};
9 chdir("$gSpoolDir") || die "chdir spool: $!\n";
13 defined($startdate= time) || &quit("failed to get time: $!");
19 # while( $bugnum > 99 ) { $bugnum = int $bugnum/10; }
20 $bugnum = $bugnum % 100;
21 $archivename = sprintf "%02d", $bugnum;
25 #get list of bugs (ie, status files)
26 opendir(DIR,"db") || &quit("opendir db: $!\n");
27 @list= grep(m/^\d+\.status$/,readdir(DIR));
28 grep(s/\.status$//,@list);
29 @list= sort { $a <=> $b } @list;
31 #process each bug (ie, status file)
32 while (length($ref=shift(@list)))
33 { print STDERR "$ref $considering\n" if $debug;
34 $bfound= &lockreadbugmerge($ref);
35 print STDERR "$ref read $bfound\n" if $debug;
37 print "$ref read ok (done $s_done)\n" if $debug;
38 (&unlockreadbugmerge($bfound), next) unless length($s_done);
39 print "$ref read done\n" if $debug;
41 if (length($s_mergedwith)) { push(@aref,split/ /,$s_mergedwith); }
42 print "$ref aref @aref\n" if $debug;
45 { print "$ref $mref check\n" if $debug;
47 { print "$ref $mref reading\n" if $debug;
48 &lockreadbug($mref) || die "huh ?";
49 print "$ref $mref read ok\n" if $debug;
52 print "$ref $mref read/not\n" if $debug;
53 $expectmerge= join(' ',grep($_ != $mref, sort { $a <=> $b } @aref));
54 $s_mergedwith eq $expectmerge ||
55 die "$ref -> $mref: ($s_mergedwith) vs. ($expectmerge) (@aref)";
56 print "$ref $mref merge-ok\n" if $debug;
57 length($s_done) || die "$ref -> $mref";
58 print "$ref $mref done-ok\n" if $debug;
59 $days= -M "db/$mref.log";
60 print "ref $mref days $days\n" if $debug;
61 if ($days <= $gRemoveAge)
62 { print "$ref $mref saved\n" if $debug; $oktoremove= 0;}
65 { print "$ref removing\n" if $debug;
67 { print "$ref removing $mref\n" if $debug;
71 $dir = "archive/" . get_archivename $mref;
73 copy( "db/$mref.log", "$dir/$mref.log" );
74 copy( "db/$mref.status", "$dir/$mref.status" );
75 copy( "db/$mref.report", "$dir/$mref.report" );
76 print("archived $mref to $dir (from $ref)\n") || &quit("output old: $!");
78 unlink("db/$mref.log", "db/$mref.status", "db/$mref.report");
79 print("deleted $mref (from $ref)\n") || &quit("output old: $!");
82 print "$ref unlocking $bfound\n" if $debug;
83 for ($i=0; $i<$bfound; $i++) { &unfilelock; }
84 print "$ref unlocking done\n" if $debug;
87 close(STDOUT) || &quit("close stdout: $!");