]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix seeking on object storage 7082/head
authorMorris Jobke <hey@morrisjobke.de>
Thu, 26 Oct 2017 14:47:54 +0000 (16:47 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Mon, 6 Nov 2017 14:28:39 +0000 (15:28 +0100)
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>
lib/private/Files/View.php

index da1c67471aba7b3591389e3b3690bf20036fdd5d..659f747a9c564e26c399abfdbad4d5131fa718d3 100644 (file)
@@ -456,8 +456,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);