[Pkg-owncloud-commits] [php-sabredav] 94/163: range requests for non-seekable streams
David Prévot
taffit at moszumanska.debian.org
Tue May 20 18:54:57 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag upstream/2.0.0_beta1
in repository php-sabredav.
commit 40451d7385e046ad6d0188c6ea128df6daa582e4
Author: jknockaert <jasper at knockaert.nl>
Date: Mon Apr 28 21:18:09 2014 +0200
range requests for non-seekable streams
Fix for range requests for non-seekable streams.
---
lib/Sabre/DAV/CorePlugin.php | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/lib/Sabre/DAV/CorePlugin.php b/lib/Sabre/DAV/CorePlugin.php
index cdca51c..f2b6c42 100644
--- a/lib/Sabre/DAV/CorePlugin.php
+++ b/lib/Sabre/DAV/CorePlugin.php
@@ -168,17 +168,16 @@ class CorePlugin extends ServerPlugin {
// New read/write stream
$newStream = fopen('php://temp','r+');
- // stream_copy_to_stream() has a bug/feature: the `whence` argument
- // is interpreted as SEEK_SET (count from absolute offset 0), while
- // for a stream it should be SEEK_CUR (count from current offset).
- // If a stream is nonseekable, the function fails. So we *emulate*
- // the correct behaviour with fseek():
- if ($start > 0) {
- if (($curOffs = ftell($body)) === false) $curOffs = 0;
- fseek($body, $start - $curOffs, SEEK_CUR);
- }
- stream_copy_to_stream($body, $newStream, $end-$start+1);
- rewind($newStream);
+ // fseek will return 0 only if $streem is seekable (and -1 otherwise)
+ // for a seekable $body stream we set the pointer write before copying it
+ // for a non-seekable $body stream we set the pointer on the copy
+ if ((fseek($body, $start, SEEK_SET)) === 0) {
+ stream_copy_to_stream($body, $newStream, $end-$start+1, $start);
+ rewind($newStream);
+ } else {
+ stream_copy_to_stream($body, $newStream, $end+1);
+ fseek($newStream,$start, SEEK_SET);
+ }
$response->setHeader('Content-Length', $end-$start+1);
$response->setHeader('Content-Range','bytes ' . $start . '-' . $end . '/' . $nodeSize);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list