From dfcda956429b717db426e16f7067e3d6448db884 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Mon, 15 Mar 2021 18:50:28 +0200 Subject: [PATCH] Fixed `Path cannot be empty` when viewing non-existent log file [#3270] --- CHANGELOG.md | 3 ++- system/src/Grav/Common/Helpers/LogViewer.php | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0023af0b4..9176ad7a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,12 +17,13 @@ * Fixed Grav using blueprints and form fields from disabled plugins * Fixed `FlexIndex::sortBy(['key' => 'ASC'])` having no effect * Fixed default Flex Pages collection ordering to order by filesystem path - * Fixed disappearing pages on save if `pages://` stream resolves to multiple folders where the preferred folder doesn't exist + * Fixed disappearing pages on save if `pages://` stream resolves to multiple folders where the preferred folder doesn't exist * Fixed Markdown image attribute `loading` [#3251](https://github.com/getgrav/grav/pull/3251) * Fixed `Uri::isValidExtension()` returning false positives * Fixed `page.html` returning duplicated content with `system.pages.redirect_default_route` turned on [#3130](https://github.com/getgrav/grav/issues/3130) * Fixed site redirect with redirect code failing when redirecting to sub-pages [#3035](https://github.com/getgrav/grav/pull/3035/files) * Fixed `Uncaught ValueError: Path cannot be empty` when failing to upload a file [#3265](https://github.com/getgrav/grav/issues/3265) + * Fixed `Path cannot be empty` when viewing non-existent log file [#3270](https://github.com/getgrav/grav/issues/3270) # v1.7.7 ## 02/23/2021 diff --git a/system/src/Grav/Common/Helpers/LogViewer.php b/system/src/Grav/Common/Helpers/LogViewer.php index 1e3e8d2f7..a03fde810 100644 --- a/system/src/Grav/Common/Helpers/LogViewer.php +++ b/system/src/Grav/Common/Helpers/LogViewer.php @@ -34,7 +34,7 @@ class LogViewer public function objectTail($filepath, $lines = 1, $desc = true) { $data = $this->tail($filepath, $lines); - $tailed_log = explode(PHP_EOL, $data); + $tailed_log = $data ? explode(PHP_EOL, $data) : []; $line_objects = []; foreach ($tailed_log as $line) { @@ -54,13 +54,13 @@ class LogViewer public function tail($filepath, $lines = 1) { - $f = @fopen($filepath, "rb"); + $f = $filepath ? @fopen($filepath, 'rb') : false; if ($f === false) { return false; - } else { - $buffer = ($lines < 2 ? 64 : ($lines < 10 ? 512 : 4096)); } + $buffer = ($lines < 2 ? 64 : ($lines < 10 ? 512 : 4096)); + fseek($f, -1, SEEK_END); if (fread($f, 1) != "\n") { $lines -= 1;