diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2017-11-02 14:56:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-02 14:56:51 +0100 |
commit | 687c92bfd3a51cea9024236dc7357bdf81534502 (patch) | |
tree | 7f34c3636f9e78a13b2ce3353ce157bd6b623850 /lib | |
parent | 4a3893b105b5b701e2146b5f27eacdce7f436200 (diff) | |
parent | de912385e00eae5c32445ae934c1c111f90961b2 (diff) | |
download | nextcloud-server-687c92bfd3a51cea9024236dc7357bdf81534502.tar.gz nextcloud-server-687c92bfd3a51cea9024236dc7357bdf81534502.zip |
Merge pull request #6974 from nextcloud/fix-fseek-on-objectstorage
Fix seeking on object storage
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); |