]> git.donarmstrong.com Git - debbugs.git/blob - scripts/expire.in
d2284036212650886099c51a0793ac204c960734
[debbugs.git] / scripts / expire.in
1 #!/usr/bin/perl
2 # $Id: expire.in,v 1.16 2003/05/25 13:17:14 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, $data)= &lockreadbugmerge($ref);
34         print STDERR "$ref read $bfound\n" if $debug;
35     $bfound || next;
36         print "$ref read ok (done $data->{done})\n" if $debug;
37     (&unlockreadbugmerge($bfound), next) unless length($data->{done});
38         print "$ref read done\n" if $debug;
39     @aref= ($ref);
40     if (length($data->{mergedwith})) { push(@aref,split / /,$data->{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             $newdata = &lockreadbug($mref) || die "huh $mref ?";
48                 print "$ref $mref read ok\n" if $debug;
49             $bfound++;
50         } else {
51             $newdata = $data;
52         }
53         print "$ref $mref read/not\n" if $debug;
54         $expectmerge= join(' ',grep($_ != $mref, sort { $a <=> $b } @aref));
55         $newdata->{mergedwith} eq $expectmerge ||
56             die "$ref -> $mref: ($newdata->{mergedwith}) vs. ($expectmerge) (@aref)";
57                 print "$ref $mref merge-ok\n" if $debug;
58         length($newdata->{done}) || die "$ref -> $mref";
59                 print "$ref $mref done-ok\n" if $debug;
60         $days= -M "db-h/".get_hashname($mref)."/$mref.log";
61                 print "ref $mref days $days\n" if $debug;
62         if ($days <= $gRemoveAge) 
63                 { print "$ref $mref saved\n" if $debug; $oktoremove= 0; }
64     }
65     if ($oktoremove) {
66         print "$ref removing\n" if $debug;
67         for $mref (@aref) {
68                 print "$ref removing $mref\n" if $debug;
69                 my $dir = get_hashname($mref);
70                 if ( $gSaveOldBugs ) {
71                         `mkdir -p "archive/$dir"`;
72                         link( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" ) || copy( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" );
73                         link( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" ) || copy( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" );
74                         link( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" ) || copy( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" );
75                         print("archived $mref to archive/$dir (from $ref)\n") || &quit("output old: $!");
76                 }
77                 unlink("db-h/$dir/$mref.log", "db-h/$dir/$mref.status", "db-h/$dir/$mref.report");
78                 print("deleted $mref (from $ref)\n") || &quit("output old: $!");
79                 bughook_archive($mref);
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: $!");