Skip to content

Commit 6f28431

Browse files
christophvwColinFinck
authored andcommitted
[TESTMAN] download the log to a local temp file instead of opening the http stream
1 parent 890e94a commit 6f28431

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

www/www.reactos.org/testman/webservice/buildbot_aggregator.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,27 @@
6262
if ($stmt->fetchColumn())
6363
throw new ErrorMessageException("The script has already processed this build before!");
6464

65-
// Read the Buildslave test log.
65+
// Download the log to a temp file
66+
$tmpfile = tempnam(sys_get_temp_dir(), "ros");
67+
if (!$tmpfile)
68+
throw new RuntimeException("Could not create temp file");
69+
6670
$logurl = sprintf(BUILDER_URL, $builder, $build);
67-
$fp = @fopen($logurl, "r");
71+
$fp = fopen($tmpfile, "w");
72+
$ch = curl_init($logurl);
73+
curl_setopt($ch, CURLOPT_FILE, $fp);
74+
curl_setopt($ch, CURLOPT_HEADER, 0);
75+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
76+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
77+
$result = curl_exec($ch);
78+
curl_close($ch);
79+
fclose($fp);
80+
81+
if (!$result)
82+
throw new RuntimeException("Could not read the full log");
83+
84+
// Read the Buildslave test log.
85+
$fp = @fopen($tmpfile, "r");
6886
if (!$fp)
6987
throw new RuntimeException("Could not open the test log!");
7088

@@ -231,21 +249,9 @@
231249

232250
// The last thing to do is to get the total time the testing took.
233251
// Unfortunately, this is only written to the HTML log...
234-
$fp = tmpfile();
252+
$fp = @fopen($tmpfile, "rb");
235253
if (!$fp)
236-
throw new RuntimeException("Could not create a temp file");
237-
238-
// Store the log in a temp file because HTTP streams are not seekable.
239-
$ch = curl_init($logurl);
240-
curl_setopt($ch, CURLOPT_FILE, $fp);
241-
curl_setopt($ch, CURLOPT_HEADER, 0);
242-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
243-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
244-
$result = curl_exec($ch);
245-
curl_close($ch);
246-
247-
if (!$result)
248-
throw new RuntimeException("Could not read the full log");
254+
throw new RuntimeException("Could not open the test log!");
249255

250256
// get the last kB of the log
251257
if (fseek($fp, -1024, SEEK_END) != -1)
@@ -257,16 +263,21 @@
257263
}
258264

259265
fclose($fp);
266+
unlink($tmpfile);
260267

261268
// Finish this test run.
262269
$writer->finish($test_id, $perf);
263270
die("OK");
264271
}
265272
catch (ErrorMessageException $e)
266273
{
274+
if (isset($tmpfile) and $tmpfile)
275+
unlink($tmpfile);
267276
die($e->getMessage());
268277
}
269278
catch (Exception $e)
270279
{
280+
if (isset($tmpfile) and $tmpfile)
281+
unlink($tmpfile);
271282
die($e->getFile() . ":" . $e->getLine() . " - " . $e->getMessage());
272283
}

0 commit comments

Comments
 (0)