2 # $Id: expire.in,v 1.17 2003/08/06 10:57:23 cjwatson Exp $
4 # Load modules and set envirnment
6 $config_path = '/etc/debbugs';
7 $lib_path = '/usr/lib/debbugs';
9 require("$config_path/config");
10 require("$config_path/text");
11 require("$lib_path/errorlib");
12 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
14 # No $gRemoveAge means "never expire".
15 exit 0 unless $gRemoveAge;
17 chdir("$gSpoolDir") || die "chdir spool: $!\n";
21 defined($startdate= time) || &quit("failed to get time: $!");
23 #get list of bugs (ie, status files)
24 opendir(DIR,"db-h") || &quit("opendir db: $!\n");
25 @dirs = sort { $a <=> $b } grep(s,^,db-h/,, grep(m/^\d+$/,readdir(DIR)));
27 foreach my $dir (@dirs) {
29 push @list, sort { $a <=> $b } grep(s/\.status$//,grep(m/^\d+\.status$/,readdir(DIR)));
33 #process each bug (ie, status file)
34 while (length($ref=shift(@list))) {
35 print STDERR "$ref considering\n" if $debug;
36 ($bfound, $data)= &lockreadbugmerge($ref);
37 print STDERR "$ref read $bfound\n" if $debug;
39 print "$ref read ok (done $data->{done})\n" if $debug;
40 (&unlockreadbugmerge($bfound), next) unless length($data->{done});
41 print "$ref read done\n" if $debug;
43 if (length($data->{mergedwith})) { push(@aref,split / /,$data->{mergedwith}); }
44 print "$ref aref @aref\n" if $debug;
47 print "$ref $mref check\n" if $debug;
49 print "$ref $mref reading\n" if $debug;
50 $newdata = &lockreadbug($mref) || die "huh $mref ?";
51 print "$ref $mref read ok\n" if $debug;
56 print "$ref $mref read/not\n" if $debug;
57 $expectmerge= join(' ',grep($_ != $mref, sort { $a <=> $b } @aref));
58 $newdata->{mergedwith} eq $expectmerge ||
59 die "$ref -> $mref: ($newdata->{mergedwith}) vs. ($expectmerge) (@aref)";
60 print "$ref $mref merge-ok\n" if $debug;
61 length($newdata->{done}) || die "$ref -> $mref";
62 print "$ref $mref done-ok\n" if $debug;
63 $days= -M "db-h/".get_hashname($mref)."/$mref.log";
64 print "ref $mref days $days\n" if $debug;
65 if ($days <= $gRemoveAge)
66 { print "$ref $mref saved\n" if $debug; $oktoremove= 0; }
69 print "$ref removing\n" if $debug;
71 print "$ref removing $mref\n" if $debug;
72 my $dir = get_hashname($mref);
73 if ( $gSaveOldBugs ) {
74 `mkdir -p "archive/$dir"`;
75 link( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" ) || copy( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" );
76 link( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" ) || copy( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" );
77 link( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" ) || copy( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" );
78 print("archived $mref to archive/$dir (from $ref)\n") || &quit("output old: $!");
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);
85 print "$ref unlocking $bfound\n" if $debug;
86 for ($i=0; $i<$bfound; $i++) { &unfilelock; }
87 print "$ref unlocking done\n" if $debug;
90 close(STDOUT) || &quit("close stdout: $!");