#!/usr/bin/perl
-# $Id: expire.in,v 1.2 1999/09/02 22:27:29 gecko Exp $
+# $Id: expire.in,v 1.23 2005/08/09 23:12:07 cjwatson Exp $
-require('/etc/debbugs/config');
-require('/usr/lib/debbugs/errorlib');
-$ENV{'PATH'}= '/usr/lib/debbugs'.$ENV{'PATH'};
-chdir("$gSpoolDir") || die "chdir spool: $!\n";
-#push(@INC,'/usr/lib/debbugs');
+# Load modules and set environment
+use File::Copy;
+use File::Path;
+$config_path = '/etc/debbugs';
+$lib_path = '/usr/lib/debbugs';
+
+require("$config_path/config");
+require("$config_path/text");
+require("$lib_path/errorlib");
+$ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
+
+# No $gRemoveAge means "never expire".
+exit 0 unless $gRemoveAge;
-#open(DEBUG,">&4");
+chdir("$gSpoolDir") || die "chdir spool: $!\n";
+#global variables
+$debug = 0;
defined($startdate= time) || &quit("failed to get time: $!");
-opendir(DIR,"db") || &quit("opendir db: $!\n");
-@list= grep(m/^\d+\.status$/,readdir(DIR));
-grep(s/\.status$//,@list);
-@list= sort { $a <=> $b } @list;
+#get list of bugs (ie, status files)
+opendir(DIR,"db-h") || &quit("opendir db: $!\n");
+@dirs = sort { $a <=> $b } grep(s,^,db-h/,, grep(m/^\d+$/,readdir(DIR)));
+close(DIR);
+foreach my $dir (@dirs) {
+ opendir(DIR,$dir);
+ push @list, sort { $a <=> $b } grep(s/\.summary$//,grep(m/^\d+\.summary$/,readdir(DIR)));
+ close(DIR);
+}
+#process each bug (ie, status file)
while (length($ref=shift(@list))) {
-#print DEBUG "$ref $considering\n";
- $bfound= &lockreadbugmerge($ref);
-#print DEBUG "$ref read $bfound\n";
+ print "$ref considering\n" if $debug;
+ ($bfound, $data)= &lockreadbugmerge($ref);
+ print "$ref read $bfound\n" if $debug;
$bfound || next;
-#print DEBUG "$ref read ok (done $s_done)\n";
- (&unlockreadbugmerge($bfound), next) unless length($s_done);
-#print DEBUG "$ref read done\n";
+ print "$ref read ok (done $data->{done})\n" if $debug;
+ (&unlockreadbugmerge($bfound), next) unless length($data->{done});
+ print "$ref read done\n" if $debug;
@aref= ($ref);
- if (length($s_mergedwith)) { push(@aref,split/ /,$s_mergedwith); }
-#print DEBUG "$ref aref @aref\n";
+ if (length($data->{mergedwith})) {
+ push(@aref,split / /,$data->{mergedwith});
+ }
+ print "$ref aref @aref\n" if $debug;
$oktoremove= 1;
for $mref (@aref) {
-#print DEBUG "$ref $mref check\n";
+ print "$ref $mref check\n" if $debug;
if ($mref != $ref) {
-#print DEBUG "$ref $mref reading\n";
- &lockreadbug($mref) || die "huh ?";
-#print DEBUG "$ref $mref read ok\n";
+ print "$ref $mref reading\n" if $debug;
+ $newdata = &lockreadbug($mref) || die "huh $mref ?";
+ print "$ref $mref read ok\n" if $debug;
$bfound++;
+ } else {
+ $newdata = $data;
}
-#print DEBUG "$ref $mref read/not\n";
+ print "$ref $mref read/not\n" if $debug;
$expectmerge= join(' ',grep($_ != $mref, sort { $a <=> $b } @aref));
- $s_mergedwith eq $expectmerge ||
- die "$ref -> $mref: ($s_mergedwith) vs. ($expectmerge) (@aref)";
-#print DEBUG "$ref $mref merge-ok\n";
- length($s_done) || die "$ref -> $mref";
-#print DEBUG "$ref $mref done-ok\n";
- $days= -M "db/$mref.log";
-#print DEBUG "$ref $mref days $days\n";
+ $newdata->{mergedwith} eq $expectmerge ||
+ die "$ref -> $mref: ($newdata->{mergedwith}) vs. ($expectmerge) (@aref)";
+ print "$ref $mref merge-ok\n" if $debug;
+ length($newdata->{done}) || die "$ref -> $mref";
+ print "$ref $mref done-ok\n" if $debug;
+ $days= -M "db-h/".get_hashname($mref)."/$mref.log";
+ print "ref $mref days $days\n" if $debug;
if ($days <= $gRemoveAge) {
-#print DEBUG "$ref $mref saved\n";
+ print "$ref $mref saved\n" if $debug;
$oktoremove= 0;
}
}
if ($oktoremove) {
-#print DEBUG "$ref removing\n";
+ print "$ref removing\n" if $debug;
for $mref (@aref) {
-#print DEBUG "$ref removing $mref\n";
- unlink("db/$mref.log", "db/$mref.status", "db/$mref.report");
+ print "$ref removing $mref\n" if $debug;
+ my $dir = get_hashname($mref);
+ if ($gSaveOldBugs) {
+ mkpath("archive/$dir");
+ link( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" ) || copy( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" );
+ link( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" ) || copy( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" );
+ link( "db-h/$dir/$mref.summary", "archive/$dir/$mref.summary" ) || copy( "db-h/$dir/$mref.summary", "archive/$dir/$mref.summary" );
+ link( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" ) || copy( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" );
+ print("archived $mref to archive/$dir (from $ref)\n") || &quit("output old: $!");
+ }
+ unlink("db-h/$dir/$mref.log", "db-h/$dir/$mref.status", "db-h/$dir/$mref.summary", "db-h/$dir/$mref.report");
print("deleted $mref (from $ref)\n") || &quit("output old: $!");
+ bughook_archive($mref);
}
}
-#print DEBUG "$ref unlocking $bfound\n";
+ print "$ref unlocking $bfound\n" if $debug;
for ($i=0; $i<$bfound; $i++) { &unfilelock; }
-#print DEBUG "$ref unlocking done\n";
+ print "$ref unlocking done\n" if $debug;
}
close(STDOUT) || &quit("close stdout: $!");