From a72db03fdbc035bc339f875f5d71473cd928016f Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 3 Aug 2016 15:26:30 +0200 Subject: [PATCH] * EPL/Filemanager: fix PHP Fatal using file-a-file dialog (upload with setting eg. a comment) --- api/src/Vfs.php | 21 ++++++++++++++------- api/src/Vfs/Sqlfs/StreamWrapper.php | 2 +- api/src/Vfs/StreamWrapper.php | 16 +++++----------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/api/src/Vfs.php b/api/src/Vfs.php index 56895481a6..36a7ee2be1 100644 --- a/api/src/Vfs.php +++ b/api/src/Vfs.php @@ -142,30 +142,32 @@ class Vfs * * @param string $path filename with absolute path in the eGW VFS * @param string $mode 'r', 'w', ... like fopen + * @param resource $context =null context to pass to stream-wrapper * @return resource */ - static function fopen($path,$mode) + static function fopen($path, $mode, $context=null) { if ($path[0] != '/') { throw new Exception\AssertionFailed("Filename '$path' is not an absolute path!"); } - return fopen(self::PREFIX.$path,$mode); + return $context ? fopen(self::PREFIX.$path, $mode, false, $context) : fopen(self::PREFIX.$path, $mode); } /** * opendir working on just the eGW VFS: returns resource for readdir() etc. * * @param string $path filename with absolute path in the eGW VFS + * @param resource $context =null context to pass to stream-wrapper * @return resource */ - static function opendir($path) + static function opendir($path, $context=null) { if ($path[0] != '/') { throw new Exception\AssertionFailed("Directory '$path' is not an absolute path!"); } - return opendir(self::PREFIX.$path); + return $context ? opendir(self::PREFIX.$path, $context) : opendir(self::PREFIX.$path); } /** @@ -2111,13 +2113,16 @@ class Vfs if (!self::stat($target)) { self::touch($target); // create empty file, to be able to attach properties - self::$treat_as_new = true; // notify as new + // tell vfs stream-wrapper to treat file in following copy as a new file notification-wises + $context = stream_context_create(array( + self::SCHEME => array('treat_as_new' => true) + )); } self::proppatch($target, $props); } if (is_resource($tmp_name)) { - $ret = ($dest = self::fopen($target, 'w')) && + $ret = ($dest = self::fopen($target, 'w', $context)) && stream_copy_to_stream($tmp_name, $dest) !== false && fclose($dest) ? self::stat($target) : false; @@ -2125,7 +2130,9 @@ class Vfs } else { - $ret = copy($tmp_name,self::PREFIX.$target) ? self::stat($target) : false; + $ret = ($context ? copy($tmp_name, self::PREFIX.$target, $context) : + copy($tmp_name, self::PREFIX.$target)) ? + self::stat($target) : false; } if (self::LOG_LEVEL > 1 || !$ret && self::LOG_LEVEL) error_log(__METHOD__."($tmp_name, $target, ".array2string($props).") returning ".array2string($ret)); return $ret; diff --git a/api/src/Vfs/Sqlfs/StreamWrapper.php b/api/src/Vfs/Sqlfs/StreamWrapper.php index 6a73f529fc..b87ac27754 100644 --- a/api/src/Vfs/Sqlfs/StreamWrapper.php +++ b/api/src/Vfs/Sqlfs/StreamWrapper.php @@ -900,7 +900,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface { return false; } - if (is_null($time)) + if (!$time) { return true; // new (empty) file created with current mod time } diff --git a/api/src/Vfs/StreamWrapper.php b/api/src/Vfs/StreamWrapper.php index 4d80e79414..6971e81a07 100644 --- a/api/src/Vfs/StreamWrapper.php +++ b/api/src/Vfs/StreamWrapper.php @@ -291,13 +291,6 @@ class StreamWrapper implements StreamWrapperIface return null; } - /** - * Can be used from egw_vfs to tell vfs notifications to treat an opened file as a new file - * - * @var boolean - */ - static protected $treat_as_new; - /** * This method is called immediately after your stream object is created. * @@ -335,11 +328,12 @@ class StreamWrapper implements StreamWrapperIface $this->opened_stream_is_new = !$stat; // are we requested to treat the opened file as new file (only for files opened NOT for reading) - if ($mode[0] != 'r' && !$this->opened_stream_is_new && self::$treat_as_new) + if ($mode[0] != 'r' && !$this->opened_stream_is_new && $this->context && + ($opts = stream_context_get_params($this->context)) && + $opts['options'][self::SCHEME]['treat_as_new']) { $this->opened_stream_is_new = true; - //error_log(__METHOD__."($path,$mode,...) stat=$stat, treat_as_new=".self::$treat_as_new." --> ".array2string($this->opened_stream_is_new)); - self::$treat_as_new = null; + //error_log(__METHOD__."($path,$mode,...) stat=$stat, context=".array2string($opts)." --> ".array2string($this->opened_stream_is_new)); } return true; } @@ -494,7 +488,7 @@ class StreamWrapper implements StreamWrapperIface */ function stream_metadata($path, $option, $value) { - if (!($url = $this->resolve_url_symlinks($path, $option == STREAM_META_TOUCH, false))) // true,false file need to exist, but do not resolve last component + if (!($url = $this->resolve_url_symlinks($path, $option != STREAM_META_TOUCH, false))) // true,false file need to exist, but do not resolve last component { return false; }