]> git.donarmstrong.com Git - debbugs.git/blob - scripts/expire.in
[project @ 1999-09-16 07:16:47 by gecko]
[debbugs.git] / scripts / expire.in
1 #!/usr/bin/perl
2 # $Id: expire.in,v 1.4 1999/09/16 07:16:47 gecko Exp $
3
4 # Load modules and set envirnment
5 require('/etc/debbugs/config');
6 require('/usr/lib/debbugs/errorlib');
7 use File::Copy;
8 $ENV{'PATH'}= '/usr/lib/debbugs'.$ENV{'PATH'};
9 chdir("$gSpoolDir") || die "chdir spool: $!\n";
10
11 #global variables
12 $debug = 0;
13 defined($startdate= time) || &quit("failed to get time: $!");
14
15 sub get_archivename
16 {       my $bugnum = shift;
17         my $archivename = "";
18
19 #       while( $bugnum > 99 ) { $bugnum = int $bugnum/10; }
20         $bugnum = $bugnum % 100;
21         $archivename = sprintf "%02d", $bugnum;
22         return $archivename;
23 }
24         
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;
30
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;
36     $bfound || next;
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;
40     @aref= ($ref);
41     if (length($s_mergedwith)) { push(@aref,split/ /,$s_mergedwith); }
42         print "$ref aref @aref\n" if $debug;
43     $oktoremove= 1;
44     for $mref (@aref) 
45         {       print "$ref $mref check\n" if $debug;
46         if ($mref != $ref) 
47                 {       print "$ref $mref reading\n" if $debug;
48             &lockreadbug($mref) || die "huh ?";
49                         print "$ref $mref read ok\n" if $debug;
50             $bfound++;
51         }
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;}
63     }
64     if ($oktoremove) 
65         {       print "$ref removing\n" if $debug;
66         for $mref (@aref) 
67                 {       print "$ref removing $mref\n" if $debug;
68                         if ( $gSaveOldBugs )
69                         {
70                                 my $dir;
71                                 $dir = "archive/" . get_archivename $mref;
72                                 `mkdir -p "$dir"`;
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: $!");
77                         }
78             unlink("db/$mref.log", "db/$mref.status", "db/$mref.report");
79             print("deleted $mref (from $ref)\n") || &quit("output old: $!");
80         }
81     }
82         print "$ref unlocking $bfound\n" if $debug;
83     for ($i=0; $i<$bfound; $i++) { &unfilelock; }
84         print "$ref unlocking done\n" if $debug;
85 }
86
87 close(STDOUT) || &quit("close stdout: $!");