2 # $Id: expire.in,v 1.23 2005/08/09 23:12:07 cjwatson Exp $
4 # Load modules and set environment
7 $config_path = '/etc/debbugs';
8 $lib_path = '/usr/lib/debbugs';
10 require("$config_path/config");
11 require("$config_path/text");
12 require("$lib_path/errorlib");
13 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
15 # No $gRemoveAge means "never expire".
16 exit 0 unless $gRemoveAge;
18 chdir("$gSpoolDir") || die "chdir spool: $!\n";
22 defined($startdate= time) || &quit("failed to get time: $!");
24 #get list of bugs (ie, status files)
25 opendir(DIR,"db-h") || &quit("opendir db: $!\n");
26 @dirs = sort { $a <=> $b } grep(s,^,db-h/,, grep(m/^\d+$/,readdir(DIR)));
28 foreach my $dir (@dirs) {
30 push @list, sort { $a <=> $b } grep(s/\.summary$//,grep(m/^\d+\.summary$/,readdir(DIR)));
34 #process each bug (ie, status file)
35 while (length($ref=shift(@list))) {
36 print "$ref considering\n" if $debug;
37 ($bfound, $data)= &lockreadbugmerge($ref);
38 print "$ref read $bfound\n" if $debug;
40 print "$ref read ok (done $data->{done})\n" if $debug;
41 (&unlockreadbugmerge($bfound), next) unless length($data->{done});
42 print "$ref read done\n" if $debug;
44 if (length($data->{mergedwith})) {
45 push(@aref,split / /,$data->{mergedwith});
47 print "$ref aref @aref\n" if $debug;
50 print "$ref $mref check\n" if $debug;
52 print "$ref $mref reading\n" if $debug;
53 $newdata = &lockreadbug($mref) || die "huh $mref ?";
54 print "$ref $mref read ok\n" if $debug;
59 print "$ref $mref read/not\n" if $debug;
60 $expectmerge= join(' ',grep($_ != $mref, sort { $a <=> $b } @aref));
61 $newdata->{mergedwith} eq $expectmerge ||
62 die "$ref -> $mref: ($newdata->{mergedwith}) vs. ($expectmerge) (@aref)";
63 print "$ref $mref merge-ok\n" if $debug;
64 length($newdata->{done}) || die "$ref -> $mref";
65 print "$ref $mref done-ok\n" if $debug;
66 $days= -M "db-h/".get_hashname($mref)."/$mref.log";
67 print "ref $mref days $days\n" if $debug;
68 if ($days <= $gRemoveAge) {
69 print "$ref $mref saved\n" if $debug;
74 print "$ref removing\n" if $debug;
76 print "$ref removing $mref\n" if $debug;
77 my $dir = get_hashname($mref);
79 mkpath("archive/$dir");
80 link( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" ) || copy( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" );
81 link( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" ) || copy( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" );
82 link( "db-h/$dir/$mref.summary", "archive/$dir/$mref.summary" ) || copy( "db-h/$dir/$mref.summary", "archive/$dir/$mref.summary" );
83 link( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" ) || copy( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" );
84 print("archived $mref to archive/$dir (from $ref)\n") || &quit("output old: $!");
86 unlink("db-h/$dir/$mref.log", "db-h/$dir/$mref.status", "db-h/$dir/$mref.summary", "db-h/$dir/$mref.report");
87 print("deleted $mref (from $ref)\n") || &quit("output old: $!");
88 bughook_archive($mref);
91 print "$ref unlocking $bfound\n" if $debug;
92 for ($i=0; $i<$bfound; $i++) { &unfilelock; }
93 print "$ref unlocking done\n" if $debug;
96 close(STDOUT) || &quit("close stdout: $!");