2 # $Id: expire.in,v 1.14 2002/11/17 22:45:16 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= &lockreadbugmerge($ref);
34 print STDERR "$ref read $bfound\n" if $debug;
36 print "$ref read ok (done $s_done)\n" if $debug;
37 (&unlockreadbugmerge($bfound), next) unless length($s_done);
38 print "$ref read done\n" if $debug;
40 if (length($s_mergedwith)) { push(@aref,split / /,$s_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 &lockreadbug($mref) || die "huh ?";
48 print "$ref $mref read ok\n" if $debug;
51 print "$ref $mref read/not\n" if $debug;
52 $expectmerge= join(' ',grep($_ != $mref, sort { $a <=> $b } @aref));
53 $s_mergedwith eq $expectmerge ||
54 die "$ref -> $mref: ($s_mergedwith) vs. ($expectmerge) (@aref)";
55 print "$ref $mref merge-ok\n" if $debug;
56 length($s_done) || die "$ref -> $mref";
57 print "$ref $mref done-ok\n" if $debug;
58 $days= -M "db-h/".get_hashname($mref)."/$mref.log";
59 print "ref $mref days $days\n" if $debug;
60 if ($days <= $gRemoveAge)
61 { print "$ref $mref saved\n" if $debug; $oktoremove= 0; }
64 print "$ref removing\n" if $debug;
66 print "$ref removing $mref\n" if $debug;
67 my $dir = get_hashname($mref);
68 if ( $gSaveOldBugs ) {
69 `mkdir -p "archive/$dir"`;
70 link( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" ) || copy( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" );
71 link( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" ) || copy( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" );
72 link( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" ) || copy( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" );
73 if ( open( IDXFILE, ">>archive/index" ) ) {
74 printf IDXFILE "%s %d %s\n", $s_package, $mref, $s_subject;
76 } else { print "Unable to write to index file\n"; }
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: $!");