-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ITSA-1096] Add a Patch to Work around Nextcloud Issue 31361
See: nextcloud/server#31361 (comment) (cherry picked from commit ccd0dd8)
- Loading branch information
Guy Elsmore-Paddock
committed
Mar 5, 2022
1 parent
bf03243
commit ae21e6f
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
docker/nextcloud-common/bundled-patches/sabre-http-avoid-mmap.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
diff --git a/3rdparty/sabre/http/lib/Sapi.php b/3rdparty/sabre/http/lib/Sapi.php | ||
index 73674a5a..8344bd0f 100644 | ||
--- a/3rdparty/sabre/http/lib/Sapi.php | ||
+++ b/3rdparty/sabre/http/lib/Sapi.php | ||
@@ -89,42 +89,10 @@ class Sapi | ||
if (null !== $contentLength) { | ||
$output = fopen('php://output', 'wb'); | ||
if (is_resource($body) && 'stream' == get_resource_type($body)) { | ||
- if (PHP_INT_SIZE > 4) { | ||
- // use the dedicated function on 64 Bit systems | ||
- // a workaround to make PHP more possible to use mmap based copy, see https://github.com/sabre-io/http/pull/119 | ||
- $left = (int) $contentLength; | ||
- // copy with 4MiB chunks | ||
- $chunk_size = 4 * 1024 * 1024; | ||
- stream_set_chunk_size($output, $chunk_size); | ||
- // If this is a partial response, flush the beginning bytes until the first position that is a multiple of the page size. | ||
- $contentRange = $response->getHeader('Content-Range'); | ||
- // Matching "Content-Range: bytes 1234-5678/7890" | ||
- if (null !== $contentRange && preg_match('/^bytes\s([0-9]+)-([0-9]+)\//i', $contentRange, $matches)) { | ||
- // 4kB should be the default page size on most architectures | ||
- $pageSize = 4096; | ||
- $offset = (int) $matches[1]; | ||
- $delta = ($offset % $pageSize) > 0 ? ($pageSize - $offset % $pageSize) : 0; | ||
- if ($delta > 0) { | ||
- $left -= stream_copy_to_stream($body, $output, min($delta, $left)); | ||
- } | ||
- } | ||
- while ($left > 0) { | ||
- $copied = stream_copy_to_stream($body, $output, min($left, $chunk_size)); | ||
- // stream_copy_to_stream($src, $dest, $maxLength) must return the number of bytes copied or false in case of failure | ||
- // But when the $maxLength is greater than the total number of bytes remaining in the stream, | ||
- // It returns the negative number of bytes copied | ||
- // So break the loop in such cases. | ||
- if ($copied <= 0) { | ||
- break; | ||
- } | ||
- $left -= $copied; | ||
- } | ||
- } else { | ||
- // workaround for 32 Bit systems to avoid stream_copy_to_stream | ||
- while (!feof($body)) { | ||
- fwrite($output, fread($body, 8192)); | ||
- } | ||
- } | ||
+ // workaround for 32 Bit systems to avoid stream_copy_to_stream | ||
+ while (!feof($body)) { | ||
+ fwrite($output, fread($body, 8192)); | ||
+ } | ||
} else { | ||
fwrite($output, $body, (int) $contentLength); | ||
} |