summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-01-04 15:13:02 +0100
committerRobin Appelman <robin@icewind.nl>2017-01-04 15:15:47 +0100
commit968de70bc57f6c5a88c2c688e1c466d419538709 (patch)
tree3c7dd2f6882475dfa04064a51f0fa3b440346765
parent9dbcc1a177ea490d20c49186a8f8090342ecb5a9 (diff)
downloadnextcloud-server-968de70bc57f6c5a88c2c688e1c466d419538709.tar.gz
nextcloud-server-968de70bc57f6c5a88c2c688e1c466d419538709.zip
remove the need to register the quota streamwrapper globally
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/base.php1
-rw-r--r--lib/private/Files/Stream/Quota.php94
-rw-r--r--tests/lib/Files/Stream/QuotaTest.php5
3 files changed, 21 insertions, 79 deletions
diff --git a/lib/base.php b/lib/base.php
index 3ab41f37599..38b07f1b308 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -669,7 +669,6 @@ class OC {
// register the stream wrappers
stream_wrapper_register('static', 'OC\Files\Stream\StaticStream');
stream_wrapper_register('close', 'OC\Files\Stream\Close');
- stream_wrapper_register('quota', 'OC\Files\Stream\Quota');
\OC::$server->getEventLogger()->start('init_session', 'Initialize session');
OC_App::loadApps(array('session'));
diff --git a/lib/private/Files/Stream/Quota.php b/lib/private/Files/Stream/Quota.php
index f064ca6c011..624a2021b9c 100644
--- a/lib/private/Files/Stream/Quota.php
+++ b/lib/private/Files/Stream/Quota.php
@@ -25,61 +25,44 @@
namespace OC\Files\Stream;
+use Icewind\Streams\Wrapper;
+
/**
* stream wrapper limits the amount of data that can be written to a stream
*
- * usage: void \OC\Files\Stream\Quota::register($id, $stream, $limit)
- * or: resource \OC\Files\Stream\Quota::wrap($stream, $limit)
+ * usage: resource \OC\Files\Stream\Quota::wrap($stream, $limit)
*/
-class Quota {
- private static $streams = array();
-
- /**
- * @var resource $source
- */
- private $source;
-
+class Quota extends Wrapper {
/**
* @var int $limit
*/
private $limit;
/**
- * @param string $id
- * @param resource $stream
- * @param int $limit
- */
- public static function register($id, $stream, $limit) {
- self::$streams[$id] = array($stream, $limit);
- }
-
- /**
- * remove all registered streams
- */
- public static function clear() {
- self::$streams = array();
- }
-
- /**
* @param resource $stream
* @param int $limit
* @return resource
*/
static public function wrap($stream, $limit) {
- $id = uniqid();
- self::register($id, $stream, $limit);
- $meta = stream_get_meta_data($stream);
- return fopen('quota://' . $id, $meta['mode']);
+ $context = stream_context_create(array(
+ 'quota' => array(
+ 'source' => $stream,
+ 'limit' => $limit
+ )
+ ));
+ return Wrapper::wrapSource($stream, $context, 'quota', self::class);
}
public function stream_open($path, $mode, $options, &$opened_path) {
- $id = substr($path, strlen('quota://'));
- if (isset(self::$streams[$id])) {
- list($this->source, $this->limit) = self::$streams[$id];
- return true;
- } else {
- return false;
- }
+ $context = $this->loadContext('quota');
+ $this->source = $context['source'];
+ $this->limit = $context['limit'];
+
+ return true;
+ }
+
+ public function dir_opendir($path, $options) {
+ return false;
}
public function stream_seek($offset, $whence = SEEK_SET) {
@@ -103,10 +86,6 @@ class Quota {
return fseek($this->source, $offset, $whence) === 0;
}
- public function stream_tell() {
- return ftell($this->source);
- }
-
public function stream_read($count) {
$this->limit -= $count;
return fread($this->source, $count);
@@ -121,37 +100,4 @@ class Quota {
$this->limit -= $size;
return fwrite($this->source, $data);
}
-
- public function stream_set_option($option, $arg1, $arg2) {
- switch ($option) {
- case STREAM_OPTION_BLOCKING:
- stream_set_blocking($this->source, $arg1);
- break;
- case STREAM_OPTION_READ_TIMEOUT:
- stream_set_timeout($this->source, $arg1, $arg2);
- break;
- case STREAM_OPTION_WRITE_BUFFER:
- stream_set_write_buffer($this->source, $arg1, $arg2);
- }
- }
-
- public function stream_stat() {
- return fstat($this->source);
- }
-
- public function stream_lock($mode) {
- return flock($this->source, $mode);
- }
-
- public function stream_flush() {
- return fflush($this->source);
- }
-
- public function stream_eof() {
- return feof($this->source);
- }
-
- public function stream_close() {
- fclose($this->source);
- }
}
diff --git a/tests/lib/Files/Stream/QuotaTest.php b/tests/lib/Files/Stream/QuotaTest.php
index d084f0c769c..24b0e7f9474 100644
--- a/tests/lib/Files/Stream/QuotaTest.php
+++ b/tests/lib/Files/Stream/QuotaTest.php
@@ -9,14 +9,11 @@
namespace Test\Files\Stream;
class QuotaTest extends \Test\TestCase {
- protected function tearDown() {
- \OC\Files\Stream\Quota::clear();
- parent::tearDown();
- }
/**
* @param string $mode
* @param integer $limit
+ * @return resource
*/
protected function getStream($mode, $limit) {
$source = fopen('php://temp', $mode);