]> git.donarmstrong.com Git - debbugs.git/blob - scripts/expire.in
c8da4dd83212e3c0f006f22f312ada6a7c99cd28
[debbugs.git] / scripts / expire.in
1 #!/usr/bin/perl
2
3 require('/etc/debbugs/config');
4 require('/usr/lib/debbugs/errorlib');
5 $ENV{'PATH'}= '/usr/lib/debbugs'.$ENV{'PATH'};
6 chdir("$gSpoolDir") || die "chdir spool: $!\n";
7 #push(@INC,'/usr/lib/debbugs');
8
9 #open(DEBUG,">&4");
10
11 defined($startdate= time) || &quit("failed to get time: $!");
12
13 opendir(DIR,"db") || &quit("opendir db: $!\n");
14 @list= grep(m/^\d+\.status$/,readdir(DIR));
15 grep(s/\.status$//,@list);
16 @list= sort { $a <=> $b } @list;
17
18 while (length($ref=shift(@list))) {
19 #print DEBUG "$ref $considering\n";
20     $bfound= &lockreadbugmerge($ref);
21 #print DEBUG "$ref read $bfound\n";
22     $bfound || next;
23 #print DEBUG "$ref read ok (done $s_done)\n";
24     (&unlockreadbugmerge($bfound), next) unless length($s_done);
25 #print DEBUG "$ref read done\n";
26     @aref= ($ref);
27     if (length($s_mergedwith)) { push(@aref,split/ /,$s_mergedwith); }
28 #print DEBUG "$ref aref @aref\n";
29     $oktoremove= 1;
30     for $mref (@aref) {
31 #print DEBUG "$ref $mref check\n";
32         if ($mref != $ref) {
33 #print DEBUG "$ref $mref reading\n";
34             &lockreadbug($mref) || die "huh ?";
35 #print DEBUG "$ref $mref read ok\n";
36             $bfound++;
37         }
38 #print DEBUG "$ref $mref read/not\n";
39         $expectmerge= join(' ',grep($_ != $mref, sort { $a <=> $b } @aref));
40         $s_mergedwith eq $expectmerge ||
41             die "$ref -> $mref: ($s_mergedwith) vs. ($expectmerge) (@aref)";
42 #print DEBUG "$ref $mref merge-ok\n";
43         length($s_done) || die "$ref -> $mref";
44 #print DEBUG "$ref $mref done-ok\n";
45         $days= -M "db/$mref.log";
46 #print DEBUG "$ref $mref days $days\n";
47         if ($days <= $gRemoveAge) {
48 #print DEBUG "$ref $mref saved\n";
49             $oktoremove= 0;
50         }
51     }
52     if ($oktoremove) {
53 #print DEBUG "$ref removing\n";
54         for $mref (@aref) {
55 #print DEBUG "$ref removing $mref\n";
56             unlink("db/$mref.log", "db/$mref.status", "db/$mref.report");
57             print("deleted $mref (from $ref)\n") || &quit("output old: $!");
58         }
59     }
60 #print DEBUG "$ref unlocking $bfound\n";
61     for ($i=0; $i<$bfound; $i++) { &unfilelock; }
62 #print DEBUG "$ref unlocking done\n";
63 }
64
65 close(STDOUT) || &quit("close stdout: $!");