]> git.donarmstrong.com Git - debbugs.git/blob - scripts/expire.in
[project @ 2003-01-29 10:48:02 by cjwatson]
[debbugs.git] / scripts / expire.in
1 #!/usr/bin/perl
2 # $Id: expire.in,v 1.14 2002/11/17 22:45:16 cjwatson Exp $
3
4 # Load modules and set envirnment
5 use File::Copy;
6 $config_path = '/etc/debbugs';
7 $lib_path = '/usr/lib/debbugs';
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 #get list of bugs (ie, status files)
21 opendir(DIR,"db-h") || &quit("opendir db: $!\n");
22 @dirs = sort { $a <=> $b } grep(s,^,db-h/,, grep(m/^\d+$/,readdir(DIR)));
23 close(DIR);
24 foreach my $dir (@dirs) {
25         opendir(DIR,$dir);
26         push @list, sort { $a <=> $b } grep(s/\.status$//,grep(m/^\d+\.status$/,readdir(DIR)));
27         close(DIR);
28 }
29
30 #process each bug (ie, status file)
31 while (length($ref=shift(@list))) {
32         print STDERR "$ref considering\n" if $debug;
33     $bfound= &lockreadbugmerge($ref);
34         print STDERR "$ref read $bfound\n" if $debug;
35     $bfound || next;
36         print "$ref read ok (done $s_done)\n" if $debug;
37     (&unlockreadbugmerge($bfound), next) unless length($s_done);
38         print "$ref read done\n" if $debug;
39     @aref= ($ref);
40     if (length($s_mergedwith)) { push(@aref,split / /,$s_mergedwith); }
41         print "$ref aref @aref\n" if $debug;
42     $oktoremove= 1;
43     for $mref (@aref) {
44         print "$ref $mref check\n" if $debug;
45         if ($mref != $ref) {
46                 print "$ref $mref reading\n" if $debug;
47             &lockreadbug($mref) || die "huh ?";
48                 print "$ref $mref read ok\n" if $debug;
49             $bfound++;
50         }
51         print "$ref $mref read/not\n" if $debug;
52         $expectmerge= join(' ',grep($_ != $mref, sort { $a <=> $b } @aref));
53         $s_mergedwith eq $expectmerge ||
54             die "$ref -> $mref: ($s_mergedwith) vs. ($expectmerge) (@aref)";
55                 print "$ref $mref merge-ok\n" if $debug;
56         length($s_done) || die "$ref -> $mref";
57                 print "$ref $mref done-ok\n" if $debug;
58         $days= -M "db-h/".get_hashname($mref)."/$mref.log";
59                 print "ref $mref days $days\n" if $debug;
60         if ($days <= $gRemoveAge) 
61                 { print "$ref $mref saved\n" if $debug; $oktoremove= 0; }
62     }
63     if ($oktoremove) {
64         print "$ref removing\n" if $debug;
65         for $mref (@aref) {
66                 print "$ref removing $mref\n" if $debug;
67                 my $dir = get_hashname($mref);
68                 if ( $gSaveOldBugs ) {
69                         `mkdir -p "archive/$dir"`;
70                         link( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" ) || copy( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" );
71                         link( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" ) || copy( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" );
72                         link( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" ) || copy( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" );
73                         if ( open( IDXFILE, ">>archive/index" ) ) {
74                                 printf IDXFILE "%s %d %s\n", $s_package, $mref, $s_subject;
75                                 close IDXFILE;
76                         } else { print "Unable to write to index file\n"; }
77                                 
78                         print("archived $mref to archive/$dir (from $ref)\n") || &quit("output old: $!");
79                 }
80                 unlink("db-h/$dir/$mref.log", "db-h/$dir/$mref.status", "db-h/$dir/$mref.report");
81                 print("deleted $mref (from $ref)\n") || &quit("output old: $!");
82                 bughook_archive($mref);
83         }
84     }
85         print "$ref unlocking $bfound\n" if $debug;
86     for ($i=0; $i<$bfound; $i++) { &unfilelock; }
87         print "$ref unlocking done\n" if $debug;
88 }
89
90 close(STDOUT) || &quit("close stdout: $!");