aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2011-02-01 00:47:24 +0100
committerLaurent Bachelier <laurent@bachelier.name>2011-02-01 00:47:24 +0100
commit0dcfcb63a6dcc31009e091b97a52ff90e0777e8a (patch)
tree481c8d9333541ec49b639e2c6bb37ccc2e704d4a
parentColor class and first color usage in spawn (diff)
downloadsymfttpd-0dcfcb63a6dcc31009e091b97a52ff90e0777e8a.tar.xz
Handle file truncation
-rw-r--r--lib/Tail.php15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/Tail.php b/lib/Tail.php
index 10d20a1..00f21ae 100644
--- a/lib/Tail.php
+++ b/lib/Tail.php
@@ -40,10 +40,23 @@ class Tail
else
{
fseek($fd, $this->pos, SEEK_SET);
- // TODO handle file truncation
}
$line = fgets($fd);
$this->pos = ftell($fd);
+
+ if ($line === false)
+ {
+ /* Detect file truncation.
+ * There seem to be no better way, as fseek will accept
+ * to go over EOF and fgets will not handle it differently either.
+ */
+ $stat = fstat($fd);
+ if ($stat['size'] < $this->pos)
+ {
+ // rewind
+ $this->pos = 0;
+ }
+ }
fclose($fd);
return $line;