Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna committed Nov 18, 2016
1 parent 6cd5a0a commit da935d5
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
4 changes: 3 additions & 1 deletion include/common.php
Expand Up @@ -2177,7 +2177,9 @@ function extract_tar($filename, $dirName)
return true;
}


$tar = new Archive_Tar($filename);
$tar->setErrorHandling(PEAR_ERROR_PRINT);
//$tar->setErrorHandling(PEAR_ERROR_PRINT);
PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_ERROR);
return $tar->extract($dirName);
}
45 changes: 32 additions & 13 deletions include/ctestparser.php
Expand Up @@ -151,10 +151,12 @@ function parse_put_submission($filehandler, $projectid, $expected_md5)
if (!$expected_md5) {
return false;
}
add_log('Started parse_put_submission: ' . time(), 'parse_put_submission', LOG_INFO);

$buildfile_row = pdo_single_row_query(
"SELECT * FROM buildfile WHERE md5='$expected_md5' LIMIT 1");
if (empty($buildfile_row)) {
add_log('Empty buildfile_row: ' . time(), 'parse_put_submission', LOG_INFO);
return false;
}

Expand All @@ -173,14 +175,18 @@ function parse_put_submission($filehandler, $projectid, $expected_md5)
(SELECT siteid FROM build WHERE id=$buildid)");
$sitename = $row['name'];

add_log('Determining filename: ' . time(), 'parse_put_submission', LOG_INFO);

global $CDASH_BACKUP_TIMEFRAME;
if ($CDASH_BACKUP_TIMEFRAME == '0') {
// if ($CDASH_BACKUP_TIMEFRAME == '0') {
$meta_data = stream_get_meta_data($filehandler);
$filename = $meta_data['uri'];
} else {
$filename = writeBackupFile($filehandler, '', $projectname, $buildname,
$sitename, $stamp, $buildfile_row['filename']);
}
// } else {
// $filename = writeBackupFile($filehandler, '', $projectname, $buildname,
// $sitename, $stamp, $buildfile_row['filename']);
// }

add_log('Wrote backup file: ' . time(), 'parse_put_submission', LOG_INFO);

// Instantiate a buildfile object so we can delete it from the database
// once we're done parsing it.
Expand Down Expand Up @@ -213,10 +219,15 @@ function parse_put_submission($filehandler, $projectid, $expected_md5)
}
$handler = new $className($buildid);

add_log('Parsing file: ' . time(), 'parse_put_submission', LOG_INFO);

// Parse the file.
$handler->Parse($filename);
check_for_immediate_deletion($filename);
$buildfile->Delete();

add_log('Returning from parse_put_submission: ' . time(), 'parse_put_submission', LOG_INFO);

return true;
}

Expand All @@ -228,6 +239,7 @@ function ctest_parse($filehandler, $projectid, $expected_md5 = '', $do_checksum
require_once 'include/common.php';
require_once 'models/project.php';
include 'include/version.php';
add_log('Started parsing: ' . time(), 'ctest_parse', LOG_INFO);

global $CDASH_USE_LOCAL_DIRECTORY;

Expand All @@ -243,6 +255,8 @@ function ctest_parse($filehandler, $projectid, $expected_md5 = '', $do_checksum
return true;
}

add_log('Started file reading: ' . time(), 'ctest_parse', LOG_INFO);

$content = fread($filehandler, 8192);
$handler = null;
$parser = xml_parser_create();
Expand Down Expand Up @@ -308,10 +322,12 @@ function ctest_parse($filehandler, $projectid, $expected_md5 = '', $do_checksum
return false;
}

add_log('Started XML parsing: ' . time(), 'ctest_parse', LOG_INFO);
xml_set_element_handler($parser, array($handler, 'startElement'), array($handler, 'endElement'));
xml_set_character_data_handler($parser, array($handler, 'text'));
xml_parse($parser, $content, false);


$projectname = get_project_name($projectid);

$sitename = '';
Expand Down Expand Up @@ -340,16 +356,16 @@ function ctest_parse($filehandler, $projectid, $expected_md5 = '', $do_checksum
// If backups are disabled, switch the filename to that of the existing handle
// Otherwise, create a backup file and process from that
global $CDASH_BACKUP_TIMEFRAME;
if ($CDASH_BACKUP_TIMEFRAME == '0') {
// if ($CDASH_BACKUP_TIMEFRAME == '0') {
$meta_data = stream_get_meta_data($filehandler);
$filename = $meta_data['uri'];
} else {
$filename = writeBackupFile($filehandler, $content, $projectname, $buildname,
$sitename, $stamp, $file . '.xml');
if ($filename === false) {
return $handler;
}
}
// } else {
// $filename = writeBackupFile($filehandler, $content, $projectname, $buildname,
// $sitename, $stamp, $file . '.xml');
// if ($filename === false) {
// return $handler;
// }
// }

$statusarray = array();
$statusarray['status'] = 'OK';
Expand All @@ -369,6 +385,7 @@ function ctest_parse($filehandler, $projectid, $expected_md5 = '', $do_checksum
if ($md5error) {
displayReturnStatus($statusarray);
add_log("Checksum failure on file: $filename", 'ctest_parse', LOG_ERR, $projectid);
add_log($statusarray['message'], 'ctest_parse', LOG_ERR, $projectid);
return false;
}
}
Expand Down Expand Up @@ -412,6 +429,8 @@ function ctest_parse($filehandler, $projectid, $expected_md5 = '', $do_checksum
fclose($parseHandle);
unset($parseHandle);

add_log('Finished XML parsing: ' . time(), 'ctest_parse', LOG_INFO);

if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/ctestparser.php')) {
$parsingerror = $localParser->EndParsingFile();
}
Expand Down
3 changes: 3 additions & 0 deletions include/do_submit.php
Expand Up @@ -113,6 +113,7 @@ function do_submit($fileHandleOrSubmissionId, $projectid, $expected_md5 = '', $d
include 'config/config.php';
$filehandle = getSubmissionFileHandle($fileHandleOrSubmissionId);

add_log('Received file handle: ' . time(), 'do_submit', LOG_INFO);
if ($filehandle === false) {
// Logs will have already captured this issue at this point
return false;
Expand Down Expand Up @@ -150,6 +151,8 @@ function do_submit($fileHandleOrSubmissionId, $projectid, $expected_md5 = '', $d
return false;
}

add_log('Finished parsing: ' . time(), 'do_submit', LOG_INFO);

// Send the emails if necessary
if ($handler instanceof UpdateHandler) {
send_update_email($handler, $projectid);
Expand Down
3 changes: 3 additions & 0 deletions models/build.php
Expand Up @@ -1745,6 +1745,8 @@ public function UpdateBuild($buildid, $newErrors, $newWarnings)
}
}



$num_clauses = count($clauses);
if ($num_clauses > 0) {
$query = 'UPDATE build SET ' . $clauses[0];
Expand All @@ -1765,6 +1767,7 @@ public function UpdateBuild($buildid, $newErrors, $newWarnings)
$row = pdo_single_row_query(
"SELECT parentid FROM build WHERE id='$buildid'");
if ($row && array_key_exists('parentid', $row) && $row['parentid'] > 0) {
add_log('build and parent: ' . $buildid . ' - ' . $row['parentid'], 'UpdateBuild', LOG_INFO);
if ($buildid == $row['parentid']) {
// Avoid infinite recursion.
// This should never happen, but we might as well be careful.
Expand Down
11 changes: 10 additions & 1 deletion public/submit.php
Expand Up @@ -82,14 +82,23 @@
$destinationFilename = $CDASH_TMP_SUBMISSION_DIRECTORY . '/' . $buildSubmissionId . '.xml';

if (copy('php://input', $destinationFilename)) {
$producer->produce(new DefaultMessage('DoSubmit', array(
add_log('producing message for submission id ' . $buildSubmissionId . ' with expected md5 of ' . $expected_md5, 'submit.php', LOG_INFO);

add_log('actual: ' . md5_file($destinationFilename) . ', expected: ' . $expected_md5, 'submit.php', LOG_INFO);

$result = $producer->produce(new DefaultMessage('DoSubmit', array(
'buildsubmissionid' => $buildSubmissionId,
'filename' => $destinationFilename,
'projectid' => $projectid,
'expected_md5' => $expected_md5,
'do_checksum' => true,
'submission_id' => 0, // The submit endpoint does not allow a submission_id
'submission_ip' => $_SERVER['REMOTE_ADDR'])));

if (!$result) {
add_log('failed to produce message: ' . print_r($result, true), 'submit.php', LOG_ERR);
}

echo '<cdash version="' . $CDASH_VERSION . "\">\n";
echo " <status>OK</status>\n";
echo " <message>Build submitted successfully.</message>\n";
Expand Down
4 changes: 4 additions & 0 deletions xml_handlers/GcovTar_handler.php
Expand Up @@ -65,6 +65,7 @@ public function __construct($buildid)
**/
public function Parse($filename)
{
add_log('Started parse .gcov: ' . time(), 'gcov::parse', LOG_INFO);
// Create a new directory where we can extract our tarball.
global $CDASH_TMP_SUBMISSION_DIRECTORY;
$dirName = $CDASH_TMP_SUBMISSION_DIRECTORY . DIRECTORY_SEPARATOR . pathinfo($filename, PATHINFO_FILENAME);
Expand All @@ -77,6 +78,8 @@ public function Parse($filename)
return false;
}

add_log('extracted tarball: ' . time(), 'gcov::parse', LOG_INFO);

// Find the data.json file and extract the source directory from it.
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dirName),
Expand Down Expand Up @@ -129,6 +132,7 @@ public function Parse($filename)
$iterator->rewind();
foreach ($iterator as $fileinfo) {
if (pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION) == 'gcov') {
add_log('Parsing .gcov file: ' . time(), 'gcov::parse', LOG_INFO);
$this->ParseGcovFile($fileinfo);
}
}
Expand Down

0 comments on commit da935d5

Please sign in to comment.