Skip to content

Commit

Permalink
Return empty string from Util::readFileEnd if file is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
samerton committed Aug 5, 2022
1 parent a0ffdbd commit dc25119
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions core/classes/Core/Util.php
Expand Up @@ -450,13 +450,17 @@ public static function readFileEnd(string $file_path, int $max_bytes = 100_000):
$start = max([$size - $max_bytes, 0]);
fseek($fp, $start);
$read_length = $size - $start;
$content = fread($fp, $read_length);
if ($start > 0) {
// Read content may contain partial line, remove it
$first_lf = strpos($content, PHP_EOL);
$content = substr($content, $first_lf + 1);
if ($read_length) {
$content = fread($fp, $read_length);
if ($start > 0) {
// Read content may contain partial line, remove it
$first_lf = strpos($content, PHP_EOL);
$content = substr($content, $first_lf + 1);
}
return $content;
}
return $content;

return '';
}

/**
Expand Down

0 comments on commit dc25119

Please sign in to comment.