#!/usr/bin/perl
-# $Id: expire.in,v 1.2 1999/09/02 22:27:29 gecko Exp $
+# This script is part of debbugs, and is released
+# under the terms of the GPL version 2, or any later
+# version at your option.
+# See the file README and COPYING for more information.
+#
+# [Other people may have contributed to this file; their copyrights
+# should go here too.]
+# Copyright 2004 by Collin Watson <cjwatson@debian.org>
+# Copyright 2007 by Don Armstrong <don@donarmstrong.com>
-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');
-#open(DEBUG,">&4");
-defined($startdate= time) || &quit("failed to get time: $!");
+use Debbugs::Control qw(bug_archive);
+use Debbugs::Status qw(bug_archiveable);
-opendir(DIR,"db") || &quit("opendir db: $!\n");
-@list= grep(m/^\d+\.status$/,readdir(DIR));
-grep(s/\.status$//,@list);
-@list= sort { $a <=> $b } @list;
+use Debbugs::Config qw(:config);
-while (length($ref=shift(@list))) {
-#print DEBUG "$ref $considering\n";
- $bfound= &lockreadbugmerge($ref);
-#print DEBUG "$ref read $bfound\n";
- $bfound || next;
-#print DEBUG "$ref read ok (done $s_done)\n";
- (&unlockreadbugmerge($bfound), next) unless length($s_done);
-#print DEBUG "$ref read done\n";
- @aref= ($ref);
- if (length($s_mergedwith)) { push(@aref,split/ /,$s_mergedwith); }
-#print DEBUG "$ref aref @aref\n";
- $oktoremove= 1;
- for $mref (@aref) {
-#print DEBUG "$ref $mref check\n";
- if ($mref != $ref) {
-#print DEBUG "$ref $mref reading\n";
- &lockreadbug($mref) || die "huh ?";
-#print DEBUG "$ref $mref read ok\n";
- $bfound++;
- }
-#print DEBUG "$ref $mref read/not\n";
- $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";
- if ($days <= $gRemoveAge) {
-#print DEBUG "$ref $mref saved\n";
- $oktoremove= 0;
- }
- }
- if ($oktoremove) {
-#print DEBUG "$ref removing\n";
- for $mref (@aref) {
-#print DEBUG "$ref removing $mref\n";
- unlink("db/$mref.log", "db/$mref.status", "db/$mref.report");
- print("deleted $mref (from $ref)\n") || &quit("output old: $!");
- }
- }
-#print DEBUG "$ref unlocking $bfound\n";
- for ($i=0; $i<$bfound; $i++) { &unfilelock; }
-#print DEBUG "$ref unlocking done\n";
+# No $gRemoveAge means "never expire".
+exit 0 unless $config{remove_age};
+
+chdir($config{spool}) || die "chdir $config{spool} failed: $!\n";
+
+#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);
+}
+
+my $bug;
+my $errors=0;
+#process each bug (ie, status file)
+while (length($bug=shift(@list))) {
+ # Weeeee.
+ next unless bug_archiveable(bug=>$bug);
+ eval {
+ bug_archive(bug=>$bug);
+ };
+ if ($@) {
+ $errors=1;
+ print STDERR "Unable to archive bug# $bug which I thought I could archive:\n$@\n";
+ }
}
-close(STDOUT) || &quit("close stdout: $!");
+exit $errors;