desactivate history for the moment (it's broken)
[build-farm.git] / import-and-analyse.pl
index cc4b42e4a820f2adaba0f383d8abd13383554aaf..84663d15f6dab8edcb10975d14d84008685ff1c9 100755 (executable)
@@ -10,6 +10,7 @@ use Digest::SHA1 qw(sha1_hex);
 use strict;
 use util;
 use File::stat;
+use File::Copy;
 use Getopt::Long;
 use hostdb;
 use data;
@@ -206,6 +207,7 @@ foreach my $host (@hosts) {
     foreach my $tree (keys %trees) {
        foreach my $compiler (@compilers) {
            my $rev;
+           my $commit;
            my $retry = 0;
            if ($opt_verbose >= 2) {
                print "Looking for a log file for $host $compiler $tree...\n";
@@ -226,7 +228,7 @@ foreach my $host (@hosts) {
                my $expression = "SELECT checksum FROM build WHERE age >= ? AND tree = ? AND host = ? AND compiler = ?";
                my $st = $dbh->prepare($expression);
            
-               $st->execute($stat->mtime, $tree, $host, $compiler);
+               $st->execute($stat->ctime, $tree, $host, $compiler);
            
                # Don't bother if we've already processed this file
                my $relevant_rows = $st->fetchall_arrayref();
@@ -259,7 +261,7 @@ foreach my $host (@hosts) {
                my $checksum = sha1_hex($data);
                if ($dbh->selectrow_array("SELECT checksum FROM build WHERE checksum = '$checksum'")) {
                    $dbh->do("UPDATE BUILD SET age = ? WHERE checksum = ?", undef, 
-                            ($stat->mtime, $checksum));
+                            ($stat->ctime, $checksum));
                    if ($opt_verbose > 1) {
                            print "retry checksum match\n";
                    }
@@ -269,8 +271,6 @@ foreach my $host (@hosts) {
                
                ($rev) = ($data =~ /BUILD REVISION: ([^\n]+)/);
 
-               my $commit;
-               
                if ($data =~ /BUILD COMMIT REVISION: (.*)/) {
                    $commit = $1;
                } else {
@@ -307,7 +307,7 @@ foreach my $host (@hosts) {
                $st->finish();
                
                $st = $dbh->prepare("INSERT INTO build (tree, revision, commit_revision, host, compiler, checksum, age, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
-               $st->execute($tree, $rev, $commit, $host, $compiler, $checksum, $stat->mtime, $status_html);
+               $st->execute($tree, $rev, $commit, $host, $compiler, $checksum, $stat->ctime, $status_html);
 
 
 #   SKIP This code, as it creates massive databases, until we get code to use the information, and a way to expire the results
@@ -377,7 +377,7 @@ foreach my $host (@hosts) {
                next;
            }
 
-           if ($rev) {
+           if ($commit) {
                # If we were able to put this into the DB (ie, a
                # one-off event, so we won't repeat this), then also
                # hard-link the log files to the revision, if we know
@@ -385,8 +385,8 @@ foreach my $host (@hosts) {
 
 
                # This ensures that the names under 'oldrev' are well known and well formed 
-               my $log_rev = $db->build_fname($tree, $host, $compiler, $rev) . ".log";
-               my $err_rev = $db->build_fname($tree, $host, $compiler, $rev) . ".err";
+               my $log_rev = $db->build_fname($tree, $host, $compiler, $commit) . ".log";
+               my $err_rev = $db->build_fname($tree, $host, $compiler, $commit) . ".err";
                if ($opt_verbose >= 2) {
                        print "Linking $logfn to $log_rev\n";
                        print "Linking $logfn to $err_rev\n";
@@ -394,7 +394,11 @@ foreach my $host (@hosts) {
                unlink $log_rev;
                unlink $err_rev;
                link($logfn . ".log", $log_rev) || die "Failed to link $logfn to $log_rev";
-               link($logfn . ".err", $err_rev) || die "Failed to link $logfn to $err_rev";
+
+               # this prevents lots of links building up with err files
+               copy($logfn . ".err", $err_rev) || die "Failed to copy $logfn to $err_rev";
+               unlink($logfn . ".err");
+               link($err_rev, $logfn . ".err");
            }
        }
     }