2 # $Id: expire.in,v 1.7 2001/08/16 07:25:53 doogie Exp $
4 # Load modules and set envirnment
6 $config_path = '/org/bugs.debian.org/etc';
7 $lib_path = '/org/bugs.debian.org/scripts';
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: $!");
24 # while( $bugnum > 99 ) { $bugnum = int $bugnum/10; }
25 $bugnum = $bugnum % 100;
26 $archivename = sprintf "%02d", $bugnum;
30 #get list of bugs (ie, status files)
31 opendir(DIR,"db") || &quit("opendir db: $!\n");
32 @list= grep(m/^\d+\.status$/,readdir(DIR));
33 grep(s/\.status$//,@list);
34 @list= sort { $a <=> $b } @list;
36 #process each bug (ie, status file)
37 while (length($ref=shift(@list)))
38 { print STDERR "$ref considering\n" if $debug;
39 $bfound= &lockreadbugmerge($ref);
40 print STDERR "$ref read $bfound\n" if $debug;
42 print "$ref read ok (done $s_done)\n" if $debug;
43 (&unlockreadbugmerge($bfound), next) unless length($s_done);
44 print "$ref read done\n" if $debug;
46 if (length($s_mergedwith)) { push(@aref,split/ /,$s_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 &lockreadbug($mref) || die "huh ?";
54 print "$ref $mref read ok\n" if $debug;
57 print "$ref $mref read/not\n" if $debug;
58 $expectmerge= join(' ',grep($_ != $mref, sort { $a <=> $b } @aref));
59 $s_mergedwith eq $expectmerge ||
60 die "$ref -> $mref: ($s_mergedwith) vs. ($expectmerge) (@aref)";
61 print "$ref $mref merge-ok\n" if $debug;
62 length($s_done) || die "$ref -> $mref";
63 print "$ref $mref done-ok\n" if $debug;
64 $days= -M "db/$mref.log";
65 print "ref $mref days $days\n" if $debug;
66 if ($days <= $gRemoveAge)
67 { print "$ref $mref saved\n" if $debug; $oktoremove= 0;}
70 { print "$ref removing\n" if $debug;
72 { print "$ref removing $mref\n" if $debug;
76 $dir = "archive/" . get_archivename $mref;
78 copy( "db/$mref.log", "$dir/$mref.log" );
79 copy( "db/$mref.status", "$dir/$mref.status" );
80 copy( "db/$mref.report", "$dir/$mref.report" );
81 if ( open( IDXFILE, ">>archive/index" ) )
82 { printf IDXFILE "%s %d %s\n", $s_package, $mref, $s_subject;
84 } else { print "Unable to write to index file\n"; }
86 print("archived $mref to $dir (from $ref)\n") || &quit("output old: $!");
88 unlink("db/$mref.log", "db/$mref.status", "db/$mref.report");
89 print("deleted $mref (from $ref)\n") || &quit("output old: $!");
92 print "$ref unlocking $bfound\n" if $debug;
93 for ($i=0; $i<$bfound; $i++) { &unfilelock; }
94 print "$ref unlocking done\n" if $debug;
97 close(STDOUT) || &quit("close stdout: $!");