diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-10-26 16:47:54 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2017-10-27 12:16:28 +0200 |
commit | de912385e00eae5c32445ae934c1c111f90961b2 (patch) | |
tree | d5006dc2b0e21f2ba5d0476db5f8ee6ef50fe8f5 /lib | |
parent | 13087da3c66449caee51450619b386d605964383 (diff) | |
download | nextcloud-server-de912385e00eae5c32445ae934c1c111f90961b2.tar.gz nextcloud-server-de912385e00eae5c32445ae934c1c111f90961b2.zip |
Fix seeking on object storage
Seeking is not needed if the $from is 0, because then the pointer is already at the correct position. Additionally another fallback is added, that if the fseek fails it just uses an fread to skip the beginning of the file until it is at the correct position. This skipping is done with a chunked fread.
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/View.php | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 7fee0883a25..d69f3b45fd2 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -447,8 +447,28 @@ class View { @ob_end_clean(); $handle = $this->fopen($path, 'rb'); if ($handle) { - if (fseek($handle, $from) === 0) { - $chunkSize = 8192; // 8 kB chunks + $chunkSize = 8192; // 8 kB chunks + $startReading = true; + + if ($from !== 0 && $from !== '0' && fseek($handle, $from) !== 0) { + // forward file handle via chunked fread because fseek seem to have failed + + $end = $from + 1; + while (!feof($handle) && ftell($handle) < $end) { + $len = $from - ftell($handle); + if ($len > $chunkSize) { + $len = $chunkSize; + } + $result = fread($handle, $len); + + if ($result === false) { + $startReading = false; + break; + } + } + } + + if ($startReading) { $end = $to + 1; while (!feof($handle) && ftell($handle) < $end) { $len = $end - ftell($handle); |