|
62 | 62 | if ($stmt->fetchColumn()) |
63 | 63 | throw new ErrorMessageException("The script has already processed this build before!"); |
64 | 64 |
|
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 | + |
66 | 70 | $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"); |
68 | 86 | if (!$fp) |
69 | 87 | throw new RuntimeException("Could not open the test log!"); |
70 | 88 |
|
|
231 | 249 |
|
232 | 250 | // The last thing to do is to get the total time the testing took. |
233 | 251 | // Unfortunately, this is only written to the HTML log... |
234 | | - $fp = tmpfile(); |
| 252 | + $fp = @fopen($tmpfile, "rb"); |
235 | 253 | 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!"); |
249 | 255 |
|
250 | 256 | // get the last kB of the log |
251 | 257 | if (fseek($fp, -1024, SEEK_END) != -1) |
|
257 | 263 | } |
258 | 264 |
|
259 | 265 | fclose($fp); |
| 266 | + unlink($tmpfile); |
260 | 267 |
|
261 | 268 | // Finish this test run. |
262 | 269 | $writer->finish($test_id, $perf); |
263 | 270 | die("OK"); |
264 | 271 | } |
265 | 272 | catch (ErrorMessageException $e) |
266 | 273 | { |
| 274 | + if (isset($tmpfile) and $tmpfile) |
| 275 | + unlink($tmpfile); |
267 | 276 | die($e->getMessage()); |
268 | 277 | } |
269 | 278 | catch (Exception $e) |
270 | 279 | { |
| 280 | + if (isset($tmpfile) and $tmpfile) |
| 281 | + unlink($tmpfile); |
271 | 282 | die($e->getFile() . ":" . $e->getLine() . " - " . $e->getMessage()); |
272 | 283 | } |
0 commit comments