]> git.pld-linux.org Git - projects/buildlogs.git/commitdiff
Limit array_splice calls to lower value.
authorArkadiusz Miśkiewicz <arekm@maven.pl>
Sun, 12 Oct 2014 22:38:52 +0000 (22:38 +0000)
committerArkadiusz Miśkiewicz <arekm@maven.pl>
Sun, 12 Oct 2014 22:38:52 +0000 (22:38 +0000)
index.php

index c2f395a98ba983122c4aaecf03a51c4168f5a22b..4ae5f8f763f67b6382655e0e7696e2f9fc77357a 100644 (file)
--- a/index.php
+++ b/index.php
@@ -351,14 +351,16 @@ function dump_log($tail)
 
        $cmd = "$filter '$root_directory/$f'";
        $fd = popen($cmd, "r");
+       $line_idx = 0;
+       $processing_idx = 0;
        $toc = array();
        $err = array();
        $err_count = 0;
-       $tail_end = 0;
        $time = "";
        $out_buf = array();
        $out_buf_size = 0;
        while (($s = fgets($fd, 102400)) != false) {
+
                if (strlen($s) > 800) {
                        $s = chunk_split($s, 800, "\n    ");
                        $s = trim($s);
@@ -393,8 +395,8 @@ function dump_log($tail)
                        $err_elem = $s;
                        $s = "<span class=section id={$m['section']}>$s</span>";
                } elseif (preg_match("/^Processing files: (?P<pkg>(?P<name>.+)-[^-]+-[^-]+)/", $s, $m)) {
+                       $processing_idx = $line_idx;
                        // processing files
-                       $tail_end++;
                        $toc_elem = "files ".$m['name'];
                        $err_elem = $s;
                        $s = "<span class=section id=files-{$m['name']}>$s</span>";
@@ -402,22 +404,33 @@ function dump_log($tail)
                        $time = $m['time'];
                }
 
-               $out_buf[] = $s;
+               $out_buf[$line_idx] = $s;
                $out_buf_size++;
+
+               // if error/processing found truncate early but keep last 100 lines before error
+               if ($tail && ($err_count == 1 || ($err_count == 0 && $processing_idx == $line_idx)) && $out_buf_size > 100) {
+                       array_splice($out_buf, 0, $out_buf_size - 100);
+                       $out_buf_size = 100;
+               }
+
                // if (not in tail mode) or (in tail mode but we have an error)
-               if (!$tail || $err_count || $tail_end) {
+               if (!$tail || $err_count || $processing_idx) {
                        if ($toc_elem)
                                $toc[] = $toc_elem;
                        if ($err_elem)
                                $err[] = $err_elem;
-               } else if ($out_buf_size > 100) {
-                       // truncate to last 100 elements
-                       $out_buf_size -= 100;
-                       $out_buf = array_splice($out_buf, 0, $out_buf_size);
                }
+
+               $line_idx++;
        }
        pclose($fd);
 
+       // no errors found, no processing found but we are in tail mode
+       if ($tail && $err_count == 0 && $processing_idx == 0 && $out_buf_size > 100) {
+               array_splice($out_buf, 0, $out_buf_size - 100);
+               $out_buf_size = 100;
+       }
+
        $code = join('', $out_buf);
 
        if ($time) {
This page took 0.115895 seconds and 4 git commands to generate.