summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2017-01-10 10:21:10 +0100
committerGitHub <noreply@github.com>2017-01-10 10:21:10 +0100
commitb847dfcee934734d68a2cf6e566558d514326858 (patch)
treeae9fbb255993a8c216f4bebee9225cc9189b9c15 /lib
parentbc8e565e2ab1081f168b1e36decf39d1ea1df839 (diff)
parente40ecc1aa130c47099745cf73b7a5d7d912172e0 (diff)
downloadnextcloud-server-b847dfcee934734d68a2cf6e566558d514326858.tar.gz
nextcloud-server-b847dfcee934734d68a2cf6e566558d514326858.zip
Merge pull request #2925 from nextcloud/remove-close-wrapper
replace close:// streamwrapper with CallBackWrapper
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php3
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Archive/TAR.php19
-rw-r--r--lib/private/Archive/ZIP.php18
-rw-r--r--lib/private/Files/ObjectStore/ObjectStoreStorage.php21
-rw-r--r--lib/private/Files/Storage/DAV.php18
-rw-r--r--lib/private/Files/Stream/Close.php119
8 files changed, 32 insertions, 168 deletions
diff --git a/lib/base.php b/lib/base.php
index 0fc34b3d9b9..dc8b29932ef 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -669,9 +669,6 @@ class OC {
OC\Log\ErrorHandler::register($debug);
}
- // register the stream wrappers
- stream_wrapper_register('close', 'OC\Files\Stream\Close');
-
\OC::$server->getEventLogger()->start('init_session', 'Initialize session');
OC_App::loadApps(array('session'));
if (!self::$CLI) {
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index c32383521fd..48b457bbabe 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -554,7 +554,6 @@ return array(
'OC\\Files\\Storage\\Wrapper\\PermissionsMask' => $baseDir . '/lib/private/Files/Storage/Wrapper/PermissionsMask.php',
'OC\\Files\\Storage\\Wrapper\\Quota' => $baseDir . '/lib/private/Files/Storage/Wrapper/Quota.php',
'OC\\Files\\Storage\\Wrapper\\Wrapper' => $baseDir . '/lib/private/Files/Storage/Wrapper/Wrapper.php',
- 'OC\\Files\\Stream\\Close' => $baseDir . '/lib/private/Files/Stream/Close.php',
'OC\\Files\\Stream\\Encryption' => $baseDir . '/lib/private/Files/Stream/Encryption.php',
'OC\\Files\\Stream\\Quota' => $baseDir . '/lib/private/Files/Stream/Quota.php',
'OC\\Files\\Type\\Detection' => $baseDir . '/lib/private/Files/Type/Detection.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index ad5e39326ab..7c14ad7e847 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -584,7 +584,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Files\\Storage\\Wrapper\\PermissionsMask' => __DIR__ . '/../../..' . '/lib/private/Files/Storage/Wrapper/PermissionsMask.php',
'OC\\Files\\Storage\\Wrapper\\Quota' => __DIR__ . '/../../..' . '/lib/private/Files/Storage/Wrapper/Quota.php',
'OC\\Files\\Storage\\Wrapper\\Wrapper' => __DIR__ . '/../../..' . '/lib/private/Files/Storage/Wrapper/Wrapper.php',
- 'OC\\Files\\Stream\\Close' => __DIR__ . '/../../..' . '/lib/private/Files/Stream/Close.php',
'OC\\Files\\Stream\\Encryption' => __DIR__ . '/../../..' . '/lib/private/Files/Stream/Encryption.php',
'OC\\Files\\Stream\\Quota' => __DIR__ . '/../../..' . '/lib/private/Files/Stream/Quota.php',
'OC\\Files\\Type\\Detection' => __DIR__ . '/../../..' . '/lib/private/Files/Type/Detection.php',
diff --git a/lib/private/Archive/TAR.php b/lib/private/Archive/TAR.php
index bbd24bd05a1..07ccd09f399 100644
--- a/lib/private/Archive/TAR.php
+++ b/lib/private/Archive/TAR.php
@@ -33,6 +33,8 @@
namespace OC\Archive;
+use Icewind\Streams\CallbackWrapper;
+
class TAR extends Archive {
const PLAIN = 0;
const GZIP = 1;
@@ -359,22 +361,19 @@ class TAR extends Archive {
if ($mode == 'r' or $mode == 'rb') {
return fopen($tmpFile, $mode);
} else {
- \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
- self::$tempFiles[$tmpFile] = $path;
- return fopen('close://' . $tmpFile, $mode);
+ $handle = fopen($tmpFile, $mode);
+ return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
+ $this->writeBack($tmpFile, $path);
+ });
}
}
- private static $tempFiles = array();
-
/**
* write back temporary files
*/
- function writeBack($tmpFile) {
- if (isset(self::$tempFiles[$tmpFile])) {
- $this->addFile(self::$tempFiles[$tmpFile], $tmpFile);
- unlink($tmpFile);
- }
+ function writeBack($tmpFile, $path) {
+ $this->addFile($path, $tmpFile);
+ unlink($tmpFile);
}
/**
diff --git a/lib/private/Archive/ZIP.php b/lib/private/Archive/ZIP.php
index 9e9fe40b2b4..0ed0f48acc4 100644
--- a/lib/private/Archive/ZIP.php
+++ b/lib/private/Archive/ZIP.php
@@ -31,6 +31,8 @@
namespace OC\Archive;
+use Icewind\Streams\CallbackWrapper;
+
class ZIP extends Archive{
/**
* @var \ZipArchive zip
@@ -198,24 +200,22 @@ class ZIP extends Archive{
$ext='';
}
$tmpFile=\OCP\Files::tmpFile($ext);
- \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if($this->fileExists($path)) {
$this->extractFile($path, $tmpFile);
}
- self::$tempFiles[$tmpFile]=$path;
- return fopen('close://'.$tmpFile, $mode);
+ $handle = fopen($tmpFile, $mode);
+ return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
+ $this->writeBack($tmpFile, $path);
+ });
}
}
- private static $tempFiles=array();
/**
* write back temporary files
*/
- function writeBack($tmpFile) {
- if(isset(self::$tempFiles[$tmpFile])) {
- $this->addFile(self::$tempFiles[$tmpFile], $tmpFile);
- unlink($tmpFile);
- }
+ function writeBack($tmpFile, $path) {
+ $this->addFile($path, $tmpFile);
+ unlink($tmpFile);
}
/**
diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
index 2dcf830cc1e..ab77c21e6c4 100644
--- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php
+++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
@@ -25,16 +25,12 @@
namespace OC\Files\ObjectStore;
+use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory;
use OC\Files\Cache\CacheEntry;
use OCP\Files\ObjectStore\IObjectStore;
class ObjectStoreStorage extends \OC\Files\Storage\Common {
-
- /**
- * @var array
- */
- private static $tmpFiles = array();
/**
* @var \OCP\Files\ObjectStore\IObjectStore $objectStore
*/
@@ -291,14 +287,14 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
$ext = '';
}
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
- \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
}
- self::$tmpFiles[$tmpFile] = $path;
-
- return fopen('close://' . $tmpFile, $mode);
+ $handle = fopen($tmpFile, $mode);
+ return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
+ $this->writeBack($tmpFile, $path);
+ });
}
return false;
}
@@ -368,12 +364,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
return true;
}
- public function writeBack($tmpFile) {
- if (!isset(self::$tmpFiles[$tmpFile])) {
- return;
- }
-
- $path = self::$tmpFiles[$tmpFile];
+ public function writeBack($tmpFile, $path) {
$stat = $this->stat($path);
if (empty($stat)) {
// create new file
diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php
index ea4bbba2748..62906f9355b 100644
--- a/lib/private/Files/Storage/DAV.php
+++ b/lib/private/Files/Storage/DAV.php
@@ -36,6 +36,7 @@ namespace OC\Files\Storage;
use Exception;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Message\ResponseInterface;
+use Icewind\Streams\CallbackWrapper;
use OC\Files\Filesystem;
use OC\Files\Stream\Close;
use Icewind\Streams\IteratorDirectory;
@@ -77,8 +78,6 @@ class DAV extends Common {
private $client;
/** @var ArrayCache */
private $statCache;
- /** @var array */
- private static $tempFiles = [];
/** @var \OCP\Http\Client\IClientService */
private $httpClientService;
@@ -409,20 +408,19 @@ class DAV extends Common {
}
$tmpFile = $tempManager->getTemporaryFile($ext);
}
- Close::registerCallback($tmpFile, array($this, 'writeBack'));
- self::$tempFiles[$tmpFile] = $path;
- return fopen('close://' . $tmpFile, $mode);
+ $handle = fopen($tmpFile, $mode);
+ return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
+ $this->writeBack($tmpFile, $path);
+ });
}
}
/**
* @param string $tmpFile
*/
- public function writeBack($tmpFile) {
- if (isset(self::$tempFiles[$tmpFile])) {
- $this->uploadFile($tmpFile, self::$tempFiles[$tmpFile]);
- unlink($tmpFile);
- }
+ public function writeBack($tmpFile, $path) {
+ $this->uploadFile($tmpFile, $path);
+ unlink($tmpFile);
}
/** {@inheritdoc} */
diff --git a/lib/private/Files/Stream/Close.php b/lib/private/Files/Stream/Close.php
deleted file mode 100644
index 7cc9903c912..00000000000
--- a/lib/private/Files/Stream/Close.php
+++ /dev/null
@@ -1,119 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Files\Stream;
-
-/**
- * stream wrapper that provides a callback on stream close
- */
-class Close {
- private static $callBacks = array();
- private $path = '';
- private $source;
- private static $open = array();
-
- public function stream_open($path, $mode, $options, &$opened_path) {
- $path = substr($path, strlen('close://'));
- $this->path = $path;
- $this->source = fopen($path, $mode);
- if (is_resource($this->source)) {
- $this->meta = stream_get_meta_data($this->source);
- }
- self::$open[] = $path;
- return is_resource($this->source);
- }
-
- public function stream_seek($offset, $whence = SEEK_SET) {
- return fseek($this->source, $offset, $whence) === 0;
- }
-
- public function stream_tell() {
- return ftell($this->source);
- }
-
- public function stream_read($count) {
- return fread($this->source, $count);
- }
-
- public function stream_write($data) {
- 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) {
- flock($this->source, $mode);
- }
-
- public function stream_flush() {
- return fflush($this->source);
- }
-
- public function stream_eof() {
- return feof($this->source);
- }
-
- public function url_stat($path) {
- $path = substr($path, strlen('close://'));
- if (file_exists($path)) {
- return stat($path);
- } else {
- return false;
- }
- }
-
- public function stream_close() {
- fclose($this->source);
- if (isset(self::$callBacks[$this->path])) {
- call_user_func(self::$callBacks[$this->path], $this->path);
- }
- }
-
- public function unlink($path) {
- $path = substr($path, strlen('close://'));
- return unlink($path);
- }
-
- /**
- * @param string $path
- */
- public static function registerCallback($path, $callback) {
- self::$callBacks[$path] = $callback;
- }
-}