]> git.donarmstrong.com Git - debbugs.git/blob - scripts/expire.in
e851f94bddcfd320de015c18fdcf7802aaf51f87
[debbugs.git] / scripts / expire.in
1 #!/usr/bin/perl
2 # $Id: expire.in,v 1.7 2001/08/16 07:25:53 doogie Exp $
3
4 # Load modules and set envirnment
5 use File::Copy;
6 $config_path = '/org/bugs.debian.org/etc';
7 $lib_path = '/org/bugs.debian.org/scripts';
8
9 require("$config_path/config");
10 require("$config_path/text");
11 require("$lib_path/errorlib");
12 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
13
14 chdir("$gSpoolDir") || die "chdir spool: $!\n";
15
16 #global variables
17 $debug = 0;
18 defined($startdate= time) || &quit("failed to get time: $!");
19
20 sub get_archivename
21 {       my $bugnum = shift;
22         my $archivename = "";
23
24 #       while( $bugnum > 99 ) { $bugnum = int $bugnum/10; }
25         $bugnum = $bugnum % 100;
26         $archivename = sprintf "%02d", $bugnum;
27         return $archivename;
28 }
29         
30 #get list of bugs (ie, status files)
31 opendir(DIR,"db") || &quit("opendir db: $!\n");
32 @list= grep(m/^\d+\.status$/,readdir(DIR));
33 grep(s/\.status$//,@list);
34 @list= sort { $a <=> $b } @list;
35
36 #process each bug (ie, status file)
37 while (length($ref=shift(@list))) 
38 {       print STDERR "$ref considering\n" if $debug;
39     $bfound= &lockreadbugmerge($ref);
40         print STDERR "$ref read $bfound\n" if $debug;
41     $bfound || next;
42         print "$ref read ok (done $s_done)\n" if $debug;
43     (&unlockreadbugmerge($bfound), next) unless length($s_done);
44         print "$ref read done\n" if $debug;
45     @aref= ($ref);
46     if (length($s_mergedwith)) { push(@aref,split/ /,$s_mergedwith); }
47         print "$ref aref @aref\n" if $debug;
48     $oktoremove= 1;
49     for $mref (@aref) 
50         {       print "$ref $mref check\n" if $debug;
51         if ($mref != $ref) 
52                 {       print "$ref $mref reading\n" if $debug;
53             &lockreadbug($mref) || die "huh ?";
54                         print "$ref $mref read ok\n" if $debug;
55             $bfound++;
56         }
57                 print "$ref $mref read/not\n" if $debug;
58         $expectmerge= join(' ',grep($_ != $mref, sort { $a <=> $b } @aref));
59         $s_mergedwith eq $expectmerge ||
60             die "$ref -> $mref: ($s_mergedwith) vs. ($expectmerge) (@aref)";
61                 print "$ref $mref merge-ok\n" if $debug;
62         length($s_done) || die "$ref -> $mref";
63                 print "$ref $mref done-ok\n" if $debug;
64         $days= -M "db/$mref.log";
65                 print "ref $mref days $days\n" if $debug;
66         if ($days <= $gRemoveAge) 
67                         { print "$ref $mref saved\n" if $debug; $oktoremove= 0;}
68     }
69     if ($oktoremove) 
70         {       print "$ref removing\n" if $debug;
71         for $mref (@aref) 
72                 {       print "$ref removing $mref\n" if $debug;
73                         if ( $gSaveOldBugs )
74                         {
75                                 my $dir;
76                                 $dir = "archive/" . get_archivename $mref;
77                                 `mkdir -p "$dir"`;
78                                 copy( "db/$mref.log", "$dir/$mref.log" );
79                                 copy( "db/$mref.status", "$dir/$mref.status" );
80                                 copy( "db/$mref.report", "$dir/$mref.report" );
81                                 if ( open( IDXFILE, ">>archive/index" ) )
82                                 {       printf IDXFILE "%s %d %s\n", $s_package, $mref, $s_subject;
83                                         close IDXFILE;
84                                 } else { print "Unable to write to index file\n"; }
85                                 
86                 print("archived $mref to $dir (from $ref)\n") || &quit("output old: $!");
87                         }
88             unlink("db/$mref.log", "db/$mref.status", "db/$mref.report");
89             print("deleted $mref (from $ref)\n") || &quit("output old: $!");
90         }
91     }
92         print "$ref unlocking $bfound\n" if $debug;
93     for ($i=0; $i<$bfound; $i++) { &unfilelock; }
94         print "$ref unlocking done\n" if $debug;
95 }
96
97 close(STDOUT) || &quit("close stdout: $!");