1998-06-17 01:43:24 +04:00
|
|
|
#!/usr/bonsaitools/bin/perl --
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
1999-11-02 02:33:56 +03:00
|
|
|
# The contents of this file are subject to the Netscape Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/NPL/
|
1998-06-17 01:43:24 +04:00
|
|
|
#
|
1999-11-02 02:33:56 +03:00
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
1998-06-17 01:43:24 +04:00
|
|
|
#
|
|
|
|
# The Original Code is the Tinderbox build tool.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
1999-11-02 02:33:56 +03:00
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1998-06-19 19:32:07 +04:00
|
|
|
# Figure out which directory tinderbox is in by looking at argv[0]
|
|
|
|
|
1999-08-25 08:55:58 +04:00
|
|
|
use File::Find;
|
|
|
|
|
1998-06-19 19:32:07 +04:00
|
|
|
$tinderboxdir = $0;
|
|
|
|
$tinderboxdir =~ s:/[^/]*$::; # Remove last word, and slash before it.
|
1999-08-25 08:55:58 +04:00
|
|
|
$tinderboxdir = '.' if $tinderboxdir eq '';
|
|
|
|
$now = time();
|
|
|
|
$expire_time = $now - 7 * 24 * 60 * 60;
|
1998-06-19 19:36:21 +04:00
|
|
|
#print "tinderbox = $tinderboxdir\n";
|
1998-06-19 19:32:07 +04:00
|
|
|
|
1999-08-25 08:55:58 +04:00
|
|
|
chdir $tinderboxdir or die "Couldn't chdir to $tinderboxdir";
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-08-25 08:55:58 +04:00
|
|
|
sub files_to_remove {
|
2000-08-21 21:52:13 +04:00
|
|
|
# Remove files older than 7 days
|
|
|
|
unlink if /^\d+\.\d+\.gz$|^tbx.[0-9]+$|^warn\d.*\.html$/ and int(-M $_) > 7;
|
|
|
|
# Remove files older than 1 day
|
|
|
|
unlink if /^\d+\.\d+\.brief\.html$/ and int(-M $_) > 1;
|
1999-08-25 08:55:58 +04:00
|
|
|
}
|
|
|
|
&find(\&files_to_remove, $tinderboxdir);
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-08-25 08:55:58 +04:00
|
|
|
# Remove build.dat entries older than 7 days
|
|
|
|
#
|
|
|
|
sub log_files_to_trim {
|
2001-11-20 08:27:29 +03:00
|
|
|
return unless /^(?:notes.txt|build.dat|scrape.dat|warnings.dat)$/;
|
1999-08-25 08:55:58 +04:00
|
|
|
warn "Cleaning $File::Find::name\n";
|
|
|
|
my $file = $_;
|
|
|
|
my $range_start = 0;
|
|
|
|
my $line = 1;
|
|
|
|
my $ed_cmds = '';
|
|
|
|
open LOG, "$file";
|
|
|
|
while (<LOG>) {
|
|
|
|
$log_time = (split /\|/)[0];
|
2000-02-15 21:04:42 +03:00
|
|
|
if ($log_time =~ /(\d+)\.\d+\.gz/) {
|
|
|
|
# Log file name is first column in file. Pull time out of it.
|
|
|
|
$log_time = $1;
|
|
|
|
}
|
1999-08-25 08:55:58 +04:00
|
|
|
if ($range_start == 0 and $log_time < $expire_time) {
|
|
|
|
$range_start = $line;
|
|
|
|
} elsif ($range_start != 0 and $log_time >= $expire_time) {
|
|
|
|
if ($range_start == $line - 1) {
|
1999-08-25 09:07:45 +04:00
|
|
|
$ed_cmds = "${range_start}d\n$ed_cmds";
|
1999-08-25 08:55:58 +04:00
|
|
|
} else {
|
1999-08-25 09:07:45 +04:00
|
|
|
$ed_cmds = "$range_start,".($line - 1)."d\n$ed_cmds";
|
1999-08-25 08:55:58 +04:00
|
|
|
}
|
|
|
|
$range_start = 0;
|
|
|
|
}
|
|
|
|
$line++;
|
|
|
|
}
|
|
|
|
close LOG;
|
1999-08-25 09:07:45 +04:00
|
|
|
next if $ed_cmds eq '';
|
1999-08-25 08:55:58 +04:00
|
|
|
open ED,"| ed $file" or die "died ed'ing: $!\n";
|
|
|
|
print ED "${ed_cmds}w\nq\n";
|
|
|
|
close ED;
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
1999-08-25 08:55:58 +04:00
|
|
|
&find(\&log_files_to_trim, $tinderboxdir);
|
|
|
|
|