Skip to content

Commit

Permalink
Merge pull request #546 from nextcloud/revert/icewindstreams
Browse files Browse the repository at this point in the history
Revert icewind/streams back to 0.7.1
  • Loading branch information
nickvergessen authored Dec 7, 2020
2 parents bc99d40 + 1d17bbb commit 27a56c5
Show file tree
Hide file tree
Showing 24 changed files with 251 additions and 394 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"doctrine/dbal": "2.12.0",
"guzzlehttp/guzzle": "6.5.2",
"icewind/searchdav": "^2.0.0",
"icewind/streams": "v0.7.2",
"icewind/streams": "v0.7.1",
"league/flysystem": "^1.0",
"microsoft/azure-storage-blob": "1.5.0",
"nextcloud/lognormalizer": "^1.0",
Expand Down
19 changes: 10 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1449,19 +1449,15 @@
'Icewind\\Streams\\DirectoryFilter' => $vendorDir . '/icewind/streams/src/DirectoryFilter.php',
'Icewind\\Streams\\DirectoryWrapper' => $vendorDir . '/icewind/streams/src/DirectoryWrapper.php',
'Icewind\\Streams\\File' => $vendorDir . '/icewind/streams/src/File.php',
'Icewind\\Streams\\HashWrapper' => $vendorDir . '/icewind/streams/src/HashWrapper.php',
'Icewind\\Streams\\IteratorDirectory' => $vendorDir . '/icewind/streams/src/IteratorDirectory.php',
'Icewind\\Streams\\NullWrapper' => $vendorDir . '/icewind/streams/src/NullWrapper.php',
'Icewind\\Streams\\Path' => $vendorDir . '/icewind/streams/src/Path.php',
'Icewind\\Streams\\PathWrapper' => $vendorDir . '/icewind/streams/src/PathWrapper.php',
'Icewind\\Streams\\ReadHashWrapper' => $vendorDir . '/icewind/streams/src/ReadHashWrapper.php',
'Icewind\\Streams\\RetryWrapper' => $vendorDir . '/icewind/streams/src/RetryWrapper.php',
'Icewind\\Streams\\SeekableWrapper' => $vendorDir . '/icewind/streams/src/SeekableWrapper.php',
'Icewind\\Streams\\Url' => $vendorDir . '/icewind/streams/src/Url.php',
'Icewind\\Streams\\UrlCallback' => $vendorDir . '/icewind/streams/src/UrlCallback.php',
'Icewind\\Streams\\UrlCallback' => $vendorDir . '/icewind/streams/src/UrlCallBack.php',
'Icewind\\Streams\\Wrapper' => $vendorDir . '/icewind/streams/src/Wrapper.php',
'Icewind\\Streams\\WrapperHandler' => $vendorDir . '/icewind/streams/src/WrapperHandler.php',
'Icewind\\Streams\\WriteHashWrapper' => $vendorDir . '/icewind/streams/src/WriteHashWrapper.php',
'JmesPath\\AstRuntime' => $vendorDir . '/mtdowling/jmespath.php/src/AstRuntime.php',
'JmesPath\\CompilerRuntime' => $vendorDir . '/mtdowling/jmespath.php/src/CompilerRuntime.php',
'JmesPath\\DebugRuntime' => $vendorDir . '/mtdowling/jmespath.php/src/DebugRuntime.php',
Expand Down
1 change: 1 addition & 0 deletions composer/autoload_psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'League\\Flysystem\\' => array($vendorDir . '/league/flysystem/src'),
'JsonSchema\\' => array($vendorDir . '/justinrainbow/json-schema/src/JsonSchema'),
'JmesPath\\' => array($vendorDir . '/mtdowling/jmespath.php/src'),
'Icewind\\Streams\\Tests\\' => array($vendorDir . '/icewind/streams/tests'),
'Icewind\\Streams\\' => array($vendorDir . '/icewind/streams/src'),
'ID3Parser\\' => array($vendorDir . '/christophwurst/id3parser/src'),
'Http\\Promise\\' => array($vendorDir . '/php-http/promise/src'),
Expand Down
11 changes: 6 additions & 5 deletions composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class ComposerStaticInit2f23f73bc0cc116b4b1eee1521aa8652
),
'I' =>
array (
'Icewind\\Streams\\Tests\\' => 22,
'Icewind\\Streams\\' => 16,
'ID3Parser\\' => 10,
),
Expand Down Expand Up @@ -397,6 +398,10 @@ class ComposerStaticInit2f23f73bc0cc116b4b1eee1521aa8652
array (
0 => __DIR__ . '/..' . '/mtdowling/jmespath.php/src',
),
'Icewind\\Streams\\Tests\\' =>
array (
0 => __DIR__ . '/..' . '/icewind/streams/tests',
),
'Icewind\\Streams\\' =>
array (
0 => __DIR__ . '/..' . '/icewind/streams/src',
Expand Down Expand Up @@ -1981,19 +1986,15 @@ class ComposerStaticInit2f23f73bc0cc116b4b1eee1521aa8652
'Icewind\\Streams\\DirectoryFilter' => __DIR__ . '/..' . '/icewind/streams/src/DirectoryFilter.php',
'Icewind\\Streams\\DirectoryWrapper' => __DIR__ . '/..' . '/icewind/streams/src/DirectoryWrapper.php',
'Icewind\\Streams\\File' => __DIR__ . '/..' . '/icewind/streams/src/File.php',
'Icewind\\Streams\\HashWrapper' => __DIR__ . '/..' . '/icewind/streams/src/HashWrapper.php',
'Icewind\\Streams\\IteratorDirectory' => __DIR__ . '/..' . '/icewind/streams/src/IteratorDirectory.php',
'Icewind\\Streams\\NullWrapper' => __DIR__ . '/..' . '/icewind/streams/src/NullWrapper.php',
'Icewind\\Streams\\Path' => __DIR__ . '/..' . '/icewind/streams/src/Path.php',
'Icewind\\Streams\\PathWrapper' => __DIR__ . '/..' . '/icewind/streams/src/PathWrapper.php',
'Icewind\\Streams\\ReadHashWrapper' => __DIR__ . '/..' . '/icewind/streams/src/ReadHashWrapper.php',
'Icewind\\Streams\\RetryWrapper' => __DIR__ . '/..' . '/icewind/streams/src/RetryWrapper.php',
'Icewind\\Streams\\SeekableWrapper' => __DIR__ . '/..' . '/icewind/streams/src/SeekableWrapper.php',
'Icewind\\Streams\\Url' => __DIR__ . '/..' . '/icewind/streams/src/Url.php',
'Icewind\\Streams\\UrlCallback' => __DIR__ . '/..' . '/icewind/streams/src/UrlCallback.php',
'Icewind\\Streams\\UrlCallback' => __DIR__ . '/..' . '/icewind/streams/src/UrlCallBack.php',
'Icewind\\Streams\\Wrapper' => __DIR__ . '/..' . '/icewind/streams/src/Wrapper.php',
'Icewind\\Streams\\WrapperHandler' => __DIR__ . '/..' . '/icewind/streams/src/WrapperHandler.php',
'Icewind\\Streams\\WriteHashWrapper' => __DIR__ . '/..' . '/icewind/streams/src/WriteHashWrapper.php',
'JmesPath\\AstRuntime' => __DIR__ . '/..' . '/mtdowling/jmespath.php/src/AstRuntime.php',
'JmesPath\\CompilerRuntime' => __DIR__ . '/..' . '/mtdowling/jmespath.php/src/CompilerRuntime.php',
'JmesPath\\DebugRuntime' => __DIR__ . '/..' . '/mtdowling/jmespath.php/src/DebugRuntime.php',
Expand Down
19 changes: 10 additions & 9 deletions composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1730,31 +1730,32 @@
},
{
"name": "icewind/streams",
"version": "v0.7.2",
"version_normalized": "0.7.2.0",
"version": "v0.7.1",
"version_normalized": "0.7.1.0",
"source": {
"type": "git",
"url": "https://github.com/icewind1991/Streams.git",
"reference": "77d750ccc654c0eda4a41fedb2dbd71053755790"
"reference": "4db3ed6c366e90b958d00e1d4c6360a9b39b2121"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/icewind1991/Streams/zipball/77d750ccc654c0eda4a41fedb2dbd71053755790",
"reference": "77d750ccc654c0eda4a41fedb2dbd71053755790",
"url": "https://api.github.com/repos/icewind1991/Streams/zipball/4db3ed6c366e90b958d00e1d4c6360a9b39b2121",
"reference": "4db3ed6c366e90b958d00e1d4c6360a9b39b2121",
"shasum": ""
},
"require": {
"php": ">=5.6"
"php": ">=5.3"
},
"require-dev": {
"php-coveralls/php-coveralls": "v2.1.0",
"phpunit/phpunit": "^5.7"
"phpunit/phpunit": "^4.8",
"satooshi/php-coveralls": "v1.0.0"
},
"time": "2020-04-08T14:59:33+00:00",
"time": "2019-02-15T12:57:29+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Icewind\\Streams\\Tests\\": "tests/",
"Icewind\\Streams\\": "src/"
}
},
Expand Down
2 changes: 0 additions & 2 deletions icewind/streams/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.idea
vendor
composer.lock
build
example.php
36 changes: 19 additions & 17 deletions icewind/streams/src/CallbackWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,30 @@ class CallbackWrapper extends Wrapper {
* Wraps a stream with the provided callbacks
*
* @param resource $source
* @param callable|null $read (optional)
* @param callable|null $write (optional)
* @param callable|null $close (optional)
* @param callable|null $readDir (optional)
* @param callable|null $preClose (optional)
* @return resource|bool
* @param callable $read (optional)
* @param callable $write (optional)
* @param callable $close (optional)
* @param callable $readDir (optional)
* @return resource
*
* @throws \BadMethodCallException
*/
public static function wrap($source, $read = null, $write = null, $close = null, $readDir = null, $preClose = null) {
$context = [
'source' => $source,
'read' => $read,
'write' => $write,
'close' => $close,
'readDir' => $readDir,
'preClose' => $preClose,
];
return self::wrapSource($source, $context);
$context = stream_context_create(array(
'callback' => array(
'source' => $source,
'read' => $read,
'write' => $write,
'close' => $close,
'readDir' => $readDir,
'preClose' => $preClose,
)
));
return Wrapper::wrapSource($source, $context, 'callback', '\Icewind\Streams\CallbackWrapper');
}

protected function open() {
$context = $this->loadContext();
$context = $this->loadContext('callback');

$this->readCallback = $context['read'];
$this->writeCallback = $context['write'];
Expand Down Expand Up @@ -110,7 +112,7 @@ public function stream_write($data) {

public function stream_close() {
if (is_callable($this->preCloseCallback)) {
call_user_func($this->preCloseCallback, $this->source);
call_user_func($this->preCloseCallback, $this->loadContext('callback')['source']);
// prevent further calls by potential PHP 7 GC ghosts
$this->preCloseCallback = null;
}
Expand Down
15 changes: 9 additions & 6 deletions icewind/streams/src/CountWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,25 @@ class CountWrapper extends Wrapper {
*
* @param resource $source
* @param callable $callback
* @return resource|bool
* @return resource
*
* @throws \BadMethodCallException
*/
public static function wrap($source, $callback) {
if (!is_callable($callback)) {
throw new \InvalidArgumentException('Invalid or missing callback');
}
return self::wrapSource($source, [
'source' => $source,
'callback' => $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();
$context = $this->loadContext('count');
$this->callback = $context['callback'];
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion icewind/streams/src/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface Directory {
public function dir_opendir($path, $options);

/**
* @return string|bool
* @return string
*/
public function dir_readdir();

Expand Down
17 changes: 10 additions & 7 deletions icewind/streams/src/DirectoryFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DirectoryFilter extends DirectoryWrapper {
* @return bool
*/
public function dir_opendir($path, $options) {
$context = $this->loadContext();
$context = $this->loadContext('filter');
$this->filter = $context['filter'];
return true;
}
Expand All @@ -36,7 +36,7 @@ public function dir_opendir($path, $options) {
public function dir_readdir() {
$file = readdir($this->source);
$filter = $this->filter;
// keep reading until we have an accepted entry or we're at the end of the folder
// keep reading untill we have an accepted entry or we're at the end of the folder
while ($file !== false && $filter($file) === false) {
$file = readdir($this->source);
}
Expand All @@ -46,12 +46,15 @@ public function dir_readdir() {
/**
* @param resource $source
* @param callable $filter
* @return resource|bool
* @return resource
*/
public static function wrap($source, callable $filter) {
return self::wrapSource($source, [
'source' => $source,
'filter' => $filter
]);
$options = array(
'filter' => array(
'source' => $source,
'filter' => $filter
)
);
return self::wrapWithOptions($options, '\Icewind\Streams\DirectoryFilter');
}
}
49 changes: 45 additions & 4 deletions icewind/streams/src/DirectoryWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,37 @@

namespace Icewind\Streams;

class DirectoryWrapper extends Wrapper implements Directory {
public function stream_open($path, $mode, $options, &$opened_path) {
return false;
class DirectoryWrapper implements Directory {
/**
* @var resource
*/
public $context;

/**
* @var resource
*/
protected $source;

/**
* Load the source from the stream context and return the context options
*
* @param string $name
* @return array
* @throws \Exception
*/
protected function loadContext($name) {
$context = stream_context_get_options($this->context);
if (isset($context[$name])) {
$context = $context[$name];
} else {
throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
}
if (isset($context['source']) and is_resource($context['source'])) {
$this->source = $context['source'];
} else {
throw new \BadMethodCallException('Invalid context, source not set');
}
return $context;
}

/**
Expand All @@ -18,7 +46,7 @@ public function stream_open($path, $mode, $options, &$opened_path) {
* @return bool
*/
public function dir_opendir($path, $options) {
$this->loadContext();
$this->loadContext('dir');
return true;
}

Expand All @@ -44,4 +72,17 @@ public function dir_rewinddir() {
rewinddir($this->source);
return true;
}

/**
* @param array $options the options for the context to wrap the stream with
* @param string $class
* @return resource
*/
protected static function wrapWithOptions($options, $class) {
$context = stream_context_create($options);
stream_wrapper_register('dirwrapper', $class);
$wrapped = opendir('dirwrapper://', $context);
stream_wrapper_unregister('dirwrapper');
return $wrapped;
}
}
Loading

0 comments on commit 27a56c5

Please sign in to comment.