summaryrefslogtreecommitdiffstats
path: root/apps/files_external/3rdparty/icewind
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-08-06 13:14:08 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-08-06 13:14:08 +0200
commitdb4235d587b9cba61d7bbb711623c1998d7289c7 (patch)
tree74125255b63cf62729b83ff38160fc889ec30d63 /apps/files_external/3rdparty/icewind
parentca54166e352f4e54887dd307bb10cc60308dbc6a (diff)
downloadnextcloud-server-db4235d587b9cba61d7bbb711623c1998d7289c7.tar.gz
nextcloud-server-db4235d587b9cba61d7bbb711623c1998d7289c7.zip
Update icewind/streams
Fixes #10430 Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_external/3rdparty/icewind')
-rw-r--r--apps/files_external/3rdparty/icewind/streams/.travis.yml7
-rw-r--r--apps/files_external/3rdparty/icewind/streams/README.md4
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/CountWrapper.php106
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/Wrapper.php14
4 files changed, 121 insertions, 10 deletions
diff --git a/apps/files_external/3rdparty/icewind/streams/.travis.yml b/apps/files_external/3rdparty/icewind/streams/.travis.yml
index d2e1afaad67..68efcd2c744 100644
--- a/apps/files_external/3rdparty/icewind/streams/.travis.yml
+++ b/apps/files_external/3rdparty/icewind/streams/.travis.yml
@@ -4,11 +4,8 @@ php:
- 5.5
- 5.6
- 7.0
- - hhvm
-
-matrix:
- allow_failures:
- - php: hhvm # due to facebook/hhvm#3321
+ - 7.1
+ - 7.2
env:
global:
diff --git a/apps/files_external/3rdparty/icewind/streams/README.md b/apps/files_external/3rdparty/icewind/streams/README.md
index ca13db28e44..88ab2dd92a3 100644
--- a/apps/files_external/3rdparty/icewind/streams/README.md
+++ b/apps/files_external/3rdparty/icewind/streams/README.md
@@ -1,4 +1,4 @@
-#Streams#
+# Streams #
[![Build Status](https://travis-ci.org/icewind1991/Streams.svg?branch=master)](https://travis-ci.org/icewind1991/Streams)
[![Coverage Status](https://img.shields.io/coveralls/icewind1991/Streams.svg)](https://coveralls.io/r/icewind1991/Streams?branch=master)
@@ -6,7 +6,7 @@
Generic stream wrappers for php.
-##CallBackWrapper##
+## CallBackWrapper ##
A `CallBackWrapper` can be used to register callbacks on read, write and closing of the stream,
it wraps an existing stream and can thus be used for any stream in php
diff --git a/apps/files_external/3rdparty/icewind/streams/src/CountWrapper.php b/apps/files_external/3rdparty/icewind/streams/src/CountWrapper.php
new file mode 100644
index 00000000000..8b86ab9187c
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/streams/src/CountWrapper.php
@@ -0,0 +1,106 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Icewind\Streams;
+
+/**
+ * Wrapper that counts the amount of data read and written
+ *
+ * The following options should be passed in the context when opening the stream
+ * [
+ * 'callback' => [
+ * 'source' => resource
+ * 'callback' => function($readCount, $writeCount){}
+ * ]
+ * ]
+ *
+ * The callback will be called when the stream is closed
+ */
+class CountWrapper extends Wrapper {
+ /**
+ * @var int
+ */
+ protected $readCount = 0;
+
+ /**
+ * @var int
+ */
+ protected $writeCount = 0;
+
+ /**
+ * @var callable
+ */
+ protected $callback;
+
+ /**
+ * Wraps a stream with the provided callbacks
+ *
+ * @param resource $source
+ * @param callable $callback
+ * @return resource
+ *
+ * @throws \BadMethodCallException
+ */
+ public static function wrap($source, $callback) {
+ if (!is_callable($callback)) {
+ throw new \InvalidArgumentException('Invalid or missing callback');
+ }
+ $context = stream_context_create(array(
+ 'count' => array(
+ 'source' => $source,
+ 'callback' => $callback
+ )
+ ));
+ return Wrapper::wrapSource($source, $context, 'callback', '\Icewind\Streams\CountWrapper');
+ }
+
+ protected function open() {
+ $context = $this->loadContext('count');
+ $this->callback = $context['callback'];
+ return true;
+ }
+
+ public function dir_opendir($path, $options) {
+ return $this->open();
+ }
+
+ public function stream_open($path, $mode, $options, &$opened_path) {
+ return $this->open();
+ }
+
+ public function stream_read($count) {
+ $result = parent::stream_read($count);
+ $this->readCount += strlen($result);
+ return $result;
+ }
+
+ public function stream_write($data) {
+ $result = parent::stream_write($data);
+ $this->writeCount += strlen($data);
+ return $result;
+ }
+
+ public function stream_close() {
+ $result = parent::stream_close();
+ call_user_func($this->callback, $this->readCount, $this->writeCount);
+ return $result;
+ }
+}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/Wrapper.php b/apps/files_external/3rdparty/icewind/streams/src/Wrapper.php
index 8e52eff9a08..babd2c1a0b3 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/Wrapper.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/Wrapper.php
@@ -26,12 +26,15 @@ abstract class Wrapper implements File, Directory {
protected $source;
protected static function wrapSource($source, $context, $protocol, $class) {
+ if (!is_resource($source)) {
+ throw new \BadMethodCallException();
+ }
try {
stream_wrapper_register($protocol, $class);
- if (@rewinddir($source) === false) {
- $wrapped = fopen($protocol . '://', 'r+', false, $context);
- } else {
+ if (self::isDirectoryHandle($source)) {
$wrapped = opendir($protocol . '://', $context);
+ } else {
+ $wrapped = fopen($protocol . '://', 'r+', false, $context);
}
} catch (\BadMethodCallException $e) {
stream_wrapper_unregister($protocol);
@@ -41,6 +44,11 @@ abstract class Wrapper implements File, Directory {
return $wrapped;
}
+ protected static function isDirectoryHandle($resource) {
+ $meta = stream_get_meta_data($resource);
+ return $meta['stream_type'] == 'dir';
+ }
+
/**
* Load the source from the stream context and return the context options
*