2 # $Id: expire.in,v 1.16 2003/05/25 13:17:14 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 chdir("$gSpoolDir") || die "chdir spool: $!\n";
18 defined($startdate= time) || &quit("failed to get time: $!");
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)));
24 foreach my $dir (@dirs) {
26 push @list, sort { $a <=> $b } grep(s/\.status$//,grep(m/^\d+\.status$/,readdir(DIR)));
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;
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;
40 if (length($data->{mergedwith})) { push(@aref,split / /,$data->{mergedwith}); }
41 print "$ref aref @aref\n" if $debug;
44 print "$ref $mref check\n" if $debug;
46 print "$ref $mref reading\n" if $debug;
47 $newdata = &lockreadbug($mref) || die "huh $mref ?";
48 print "$ref $mref read ok\n" if $debug;
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; }
66 print "$ref removing\n" if $debug;
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: $!");
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);
82 print "$ref unlocking $bfound\n" if $debug;
83 for ($i=0; $i<$bfound; $i++) { &unfilelock; }
84 print "$ref unlocking done\n" if $debug;
87 close(STDOUT) || &quit("close stdout: $!");