[Pkg-owncloud-commits] [owncloud] 08/42: Fixed quota wrapper to not wrap failed fopen streams
David Prévot
taffit at moszumanska.debian.org
Wed Jan 22 21:21:48 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit 09cc0c5cc9577980e79ba6a1ba8363682395f378
Author: Vincent Petry <pvince81 at owncloud.com>
Date: Sun Jan 19 18:49:51 2014 +0100
Fixed quota wrapper to not wrap failed fopen streams
When calling fopen() on some storage types, these return false instead
of throwing an exception.
This fix makes sure that in case the stream wasn't opened (for example
when a file doesn't exist any more) the stream isn't wrapped.
Also added 'rb' as another case that doesn't need to be wrapped.
Fixes #6832
---
lib/private/files/storage/wrapper/quota.php | 2 +-
tests/lib/files/storage/wrapper/quota.php | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/lib/private/files/storage/wrapper/quota.php b/lib/private/files/storage/wrapper/quota.php
index 43016e0..a430e3e 100644
--- a/lib/private/files/storage/wrapper/quota.php
+++ b/lib/private/files/storage/wrapper/quota.php
@@ -95,7 +95,7 @@ class Quota extends Wrapper {
public function fopen($path, $mode) {
$source = $this->storage->fopen($path, $mode);
$free = $this->free_space('');
- if ($free >= 0 && $mode !== 'r') {
+ if ($source && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
return \OC\Files\Stream\Quota::wrap($source, $free);
} else {
return $source;
diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
index 9b14335..87bafb6 100644
--- a/tests/lib/files/storage/wrapper/quota.php
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -59,6 +59,20 @@ class Quota extends \Test\Files\Storage\Storage {
$this->assertEquals('foobarqwe', $instance->file_get_contents('foo'));
}
+ public function testReturnFalseWhenFopenFailed(){
+ $failStorage = $this->getMock(
+ '\OC\Files\Storage\Local',
+ array('fopen'),
+ array(array('datadir' => $this->tmpDir)));
+ $failStorage->expects($this->any())
+ ->method('fopen')
+ ->will($this->returnValue(false));
+
+ $instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $failStorage, 'quota' => 1000));
+
+ $this->assertFalse($instance->fopen('failedfopen', 'r'));
+ }
+
public function testReturnRegularStreamOnRead(){
$instance = $this->getLimitedStorage(9);
@@ -71,6 +85,11 @@ class Quota extends \Test\Files\Storage\Storage {
$meta = stream_get_meta_data($stream);
$this->assertEquals('plainfile', $meta['wrapper_type']);
fclose($stream);
+
+ $stream = $instance->fopen('foo', 'rb');
+ $meta = stream_get_meta_data($stream);
+ $this->assertEquals('plainfile', $meta['wrapper_type']);
+ fclose($stream);
}
public function testReturnQuotaStreamOnWrite(){
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list