From b65d87bc68fec39fb7e3ccd71e5dcb09accd0920 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 19 Jul 2016 11:59:16 +0200 Subject: [PATCH] fixing our wrong static methods in stream-wrapper: unlink, rmdir, mkdir, rename and url_stat (they are not static, so PHP can pass in $context) --- api/src/Link.php | 2 +- api/src/Vfs.php | 30 ++++++++----- api/src/Vfs/Dav/File.php | 2 +- api/src/Vfs/Filesystem/StreamWrapper.php | 10 ++--- api/src/Vfs/Links/StreamWrapper.php | 4 +- api/src/Vfs/Sqlfs/StreamWrapper.php | 54 +++++++++++++---------- api/src/Vfs/Sqlfs/Utils.php | 8 ++-- api/src/Vfs/StreamWrapper.php | 55 +++++++++++++----------- api/src/Vfs/StreamWrapperIface.php | 10 ++--- 9 files changed, 99 insertions(+), 76 deletions(-) diff --git a/api/src/Link.php b/api/src/Link.php index ca2ccef071..7707b4e689 100644 --- a/api/src/Link.php +++ b/api/src/Link.php @@ -1300,7 +1300,7 @@ class Link extends Link\Storage if (!is_array($fileinfo)) { $url = Vfs\Sqlfs\StreamWrapper::id2path($fileinfo); - if (!($fileinfo = Vfs::url_stat($url,STREAM_URL_STAT_QUIET))) + if (!($fileinfo = Vfs::stat($url,STREAM_URL_STAT_QUIET))) { return false; } diff --git a/api/src/Vfs.php b/api/src/Vfs.php index 492c1d9964..851f1b1e29 100644 --- a/api/src/Vfs.php +++ b/api/src/Vfs.php @@ -242,7 +242,8 @@ class Vfs extends Vfs\StreamWrapper { throw new Exception\AssertionFailed("File '$path' is not an absolute path!"); } - if (($stat = self::url_stat($path,0,$try_create_home))) + $vfs = new Vfs\StreamWrapper(); + if (($stat = $vfs->url_stat($path,0,$try_create_home))) { $stat = array_slice($stat,13); // remove numerical indices 0-12 } @@ -262,7 +263,8 @@ class Vfs extends Vfs\StreamWrapper { throw new Exception\AssertionFailed("File '$path' is not an absolute path!"); } - if (($stat = self::url_stat($path,STREAM_URL_STAT_LINK,$try_create_home))) + $vfs = new Vfs\StreamWrapper(); + if (($stat = $vfs->url_stat($path,STREAM_URL_STAT_LINK,$try_create_home))) { $stat = array_slice($stat,13); // remove numerical indices 0-12 } @@ -683,7 +685,8 @@ class Vfs extends Vfs\StreamWrapper } else { - $stat = self::url_stat($path,STREAM_URL_STAT_LINK); + $vfs = new Vfs\StreamWrapper(); + $stat = $vfs->url_stat($path,STREAM_URL_STAT_LINK); } if (!$stat) { @@ -802,11 +805,12 @@ class Vfs extends Vfs\StreamWrapper { $url = self::PREFIX . $url; } + $vfs = new Vfs\StreamWrapper(); if (is_dir($url) && !is_link($url)) { - return self::rmdir($url,0); + return $vfs->rmdir($url,0); } - return self::unlink($url); + return $vfs->unlink($url); } /** @@ -847,7 +851,8 @@ class Vfs extends Vfs\StreamWrapper { self::clearstatcache($path); - $path_user_stat[$path][$user] = self::url_stat($path, 0); + $vfs = new Vfs\StreamWrapper(); + $path_user_stat[$path][$user] = $vfs->url_stat($path, 0); self::clearstatcache($path); // we need to clear the stat-cache after the call too, as the next call might be the regular user again! } @@ -889,7 +894,8 @@ class Vfs extends Vfs\StreamWrapper // query stat array, if not given if (is_null($stat)) { - $stat = self::url_stat($path,0); + if (!isset($vfs)) $vfs = new Vfs\StreamWrapper(); + $stat = $vfs->url_stat($path,0); } //error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check)"); @@ -1346,8 +1352,11 @@ class Vfs extends Vfs\StreamWrapper */ static function has_owner_rights($path,array $stat=null) { - if (!$stat) $stat = self::url_stat($path,0); - + if (!$stat) + { + $vfs = new Vfs\StreamWrapper(); + $stat = $vfs->url_stat($path,0); + } return $stat['uid'] == self::$user || // user is the owner self::$is_root || // class runs with root rights !$stat['uid'] && $stat['gid'] && self::$is_admin; // group directory and user is an eGW admin @@ -2020,11 +2029,12 @@ class Vfs extends Vfs\StreamWrapper { if (self::is_dir($dst)) { + $vfs = new Vfs\StreamWrapper(); foreach($src as $file) { $target = self::concat($dst, self::basename($file)); - if ($file != $target && self::rename($file, $target)) + if ($file != $target && $vfs->rename($file, $target)) { $moved[] = $file; } diff --git a/api/src/Vfs/Dav/File.php b/api/src/Vfs/Dav/File.php index 78a52d00b9..28472c836c 100644 --- a/api/src/Vfs/Dav/File.php +++ b/api/src/Vfs/Dav/File.php @@ -66,7 +66,7 @@ class File extends DAV\FS\File */ function getETag() { - if (($stat = Vfs::url_stat($this->vfs_path, STREAM_URL_STAT_QUIET))) + if (($stat = Vfs::stat($this->vfs_path, STREAM_URL_STAT_QUIET))) { return '"'.$stat['ino'].':'.$stat['mtime'].':'.$stat['size'].'"'; } diff --git a/api/src/Vfs/Filesystem/StreamWrapper.php b/api/src/Vfs/Filesystem/StreamWrapper.php index b39b08d352..6646865e4a 100644 --- a/api/src/Vfs/Filesystem/StreamWrapper.php +++ b/api/src/Vfs/Filesystem/StreamWrapper.php @@ -306,7 +306,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface * @param string $url * @return boolean TRUE on success or FALSE on failure */ - static function unlink ( $url ) + function unlink ( $url ) { $path = Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH)); @@ -331,7 +331,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface * @param string $url_to * @return boolean TRUE on success or FALSE on failure */ - static function rename ( $url_from, $url_to ) + function rename ( $url_from, $url_to ) { $from = Vfs::parse_url($url_from); $to = Vfs::parse_url($url_to); @@ -381,7 +381,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE * @return boolean TRUE on success or FALSE on failure */ - static function mkdir ( $url, $mode, $options ) + function mkdir ( $url, $mode, $options ) { unset($mode); // not used, but required by interface @@ -415,7 +415,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface * @param int $options Possible values include STREAM_REPORT_ERRORS. * @return boolean TRUE on success or FALSE on failure. */ - static function rmdir ( $url, $options ) + function rmdir ( $url, $options ) { unset($options); // not used, but required by interface @@ -552,7 +552,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface * stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper! * @return array */ - static function url_stat ( $url, $flags ) + function url_stat ( $url, $flags ) { $parts = Vfs::parse_url($url); $path = Vfs::decodePath($parts['path']); diff --git a/api/src/Vfs/Links/StreamWrapper.php b/api/src/Vfs/Links/StreamWrapper.php index 9564a3aa62..e74124e875 100644 --- a/api/src/Vfs/Links/StreamWrapper.php +++ b/api/src/Vfs/Links/StreamWrapper.php @@ -137,7 +137,7 @@ class StreamWrapper extends LinksParent * stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper! * @return array */ - static function url_stat ( $url, $flags ) + function url_stat ( $url, $flags ) { $eacl_check=self::check_extended_acl($url,Vfs::READABLE); @@ -232,7 +232,7 @@ class StreamWrapper extends LinksParent * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE, we allways use recursive! * @return boolean TRUE on success or FALSE on failure */ - static function mkdir($path,$mode,$options) + function mkdir($path,$mode,$options) { unset($mode); // not used, but required by function signature diff --git a/api/src/Vfs/Sqlfs/StreamWrapper.php b/api/src/Vfs/Sqlfs/StreamWrapper.php index ab93cd8c08..fae15a835b 100644 --- a/api/src/Vfs/Sqlfs/StreamWrapper.php +++ b/api/src/Vfs/Sqlfs/StreamWrapper.php @@ -543,7 +543,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface * @param string $url * @return boolean TRUE on success or FALSE on failure */ - static function unlink ( $url, $parent_stat=null ) + function unlink ( $url, $parent_stat=null ) { if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)"); @@ -553,10 +553,10 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface if (!isset($parent_stat)) { $parent_stat = !($dir = Vfs::dirname($path)) ? false : - static::url_stat($dir, STREAM_URL_STAT_LINK); + $this->url_stat($dir, STREAM_URL_STAT_LINK); } - if (!$parent_stat || !($stat = self::url_stat($path,STREAM_URL_STAT_LINK)) || + if (!$parent_stat || !($stat = $this->url_stat($path,STREAM_URL_STAT_LINK)) || !$dir || !Vfs::check_access($dir, Vfs::WRITABLE, $parent_stat)) { self::_remove_password($url); @@ -599,7 +599,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface * @param string $url_to * @return boolean TRUE on success or FALSE on failure */ - static function rename ( $url_from, $url_to) + function rename ( $url_from, $url_to) { if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url_from,$url_to)"); @@ -693,13 +693,13 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE * @return boolean TRUE on success or FALSE on failure */ - static function mkdir ( $url, $mode, $options ) + function mkdir ( $url, $mode, $options ) { if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)"); if (self::LOG_LEVEL > 1) error_log(__METHOD__." called from:".function_backtrace()); $path = Vfs::parse_url($url,PHP_URL_PATH); - if (self::url_stat($path,STREAM_URL_STAT_QUIET)) + if ($this->url_stat($path,STREAM_URL_STAT_QUIET)) { self::_remove_password($url); if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) already exist!"); @@ -720,7 +720,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface return false; } if (($query = Vfs::parse_url($url,PHP_URL_QUERY))) $parent_path .= '?'.$query; - $parent = self::url_stat($parent_path,STREAM_URL_STAT_QUIET); + $parent = $this->url_stat($parent_path,STREAM_URL_STAT_QUIET); // check if we should also create all non-existing path components and our parent does not exist, // if yes call ourself recursive with the parent directory @@ -731,7 +731,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface { return false; } - $parent = self::url_stat($parent_path,0); + $parent = $this->url_stat($parent_path,0); } if (!$parent || !Vfs::check_access($parent_path,Vfs::WRITABLE,$parent)) { @@ -788,14 +788,14 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface * @param int $options Possible values include STREAM_REPORT_ERRORS. * @return boolean TRUE on success or FALSE on failure. */ - static function rmdir ( $url, $options ) + function rmdir ( $url, $options ) { if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)"); $path = Vfs::parse_url($url,PHP_URL_PATH); if (!($parent = Vfs::dirname($path)) || - !($stat = self::url_stat($path, 0)) || $stat['mime'] != self::DIR_MIME_TYPE || + !($stat = $this->url_stat($path, 0)) || $stat['mime'] != self::DIR_MIME_TYPE || !Vfs::check_access($parent, Vfs::WRITABLE, static::url_stat($parent,0))) { self::_remove_password($url); @@ -849,7 +849,8 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface $path = Vfs::parse_url($url,PHP_URL_PATH); - if (!($stat = self::url_stat($path,STREAM_URL_STAT_QUIET))) + $vfs = new self(); + if (!($stat = $vfs->url_stat($path,STREAM_URL_STAT_QUIET))) { // file does not exist --> create an empty one if (!($f = fopen(self::SCHEME.'://default'.$path,'w')) || !fclose($f)) @@ -860,7 +861,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface { return true; // new (empty) file created with current mod time } - $stat = self::url_stat($path,0); + $stat = $vfs->url_stat($path,0); } unset(self::$stat_cache[$path]); $stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_modified=:fs_modified,fs_modifier=:fs_modifier WHERE fs_id=:fs_id'); @@ -885,7 +886,8 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface $path = Vfs::parse_url($url,PHP_URL_PATH); - if (!($stat = self::url_stat($path,0))) + $vfs = new self(); + if (!($stat = $vfs->url_stat($path,0))) { if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!"); trigger_error("No such file or directory $url !",E_USER_WARNING); @@ -929,7 +931,8 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface $path = Vfs::parse_url($url,PHP_URL_PATH); - if (!($stat = self::url_stat($path,0))) + $vfs = new self(); + if (!($stat = $vfs->url_stat($path,0))) { if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!"); trigger_error("No such file or directory $url !",E_USER_WARNING); @@ -974,7 +977,8 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface $path = Vfs::parse_url($url,PHP_URL_PATH); - if (!($stat = self::url_stat($path,0))) + $vfs = new self(); + if (!($stat = $vfs->url_stat($path,0))) { if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no such file or directory!"); trigger_error("No such file or directory $url !",E_USER_WARNING); @@ -1018,7 +1022,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface $path = Vfs::parse_url($url,PHP_URL_PATH); - if (!($stat = self::url_stat($url,0)) || // dir not found + if (!($stat = $this->url_stat($url,0)) || // dir not found $stat['mime'] != self::DIR_MIME_TYPE || // no dir !Vfs::check_access($url,Vfs::EXECUTABLE|Vfs::READABLE,$stat)) // no access { @@ -1078,7 +1082,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface * @param boolean $eacl_access =null allows extending classes to pass the value of their check_extended_acl() method (no lsb!) * @return array */ - static function url_stat ( $url, $flags, $eacl_access=null ) + function url_stat ( $url, $flags, $eacl_access=null ) { static $max_subquery_depth=null; if (is_null($max_subquery_depth)) @@ -1187,7 +1191,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface error_log(__METHOD__."() decremented max_subquery_depth to $max_subquery_depth"); Api\Config::save_value('max_subquery_depth', $max_subquery_depth, 'phpgwapi'); if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) $GLOBALS['egw']->invalidate_session_cache(); - return self::url_stat($url, $flags, $eacl_access); + return $this->url_stat($url, $flags, $eacl_access); } self::$stat_cache[$path] = $info; @@ -1284,7 +1288,8 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface */ static function readlink($path) { - $link = !($lstat = self::url_stat($path,STREAM_URL_STAT_LINK)) || is_null($lstat['readlink']) ? false : $lstat['readlink']; + $vfs = new self(); + $link = !($lstat = $vfs->url_stat($path,STREAM_URL_STAT_LINK)) || is_null($lstat['readlink']) ? false : $lstat['readlink']; if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path') = $link"); @@ -1302,7 +1307,8 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface { if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$target','$link')"); - if (self::url_stat($link,0)) + $vfs = new self(); + if ($vfs->url_stat($link,0)) { if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') $link exists, returning false!"); return false; // $link already exists @@ -1422,7 +1428,8 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface } if (is_null($fs_id)) { - if (!($stat = self::url_stat($path,0))) + $vfs = new self(); + if (!($stat = $vfs->url_stat($path,0))) { if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) no such file or directory!"); return false; // $path not found @@ -1740,7 +1747,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface if (self::LOG_LEVEL > 1) error_log(__METHOD__."(".array2string($path).','.array2string($props)); if (!is_numeric($path)) { - if (!($stat = self::url_stat($path,0))) + if (!($stat = $vfs->url_stat($path,0))) { return false; } @@ -1807,7 +1814,8 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface { if (!is_numeric($id)) { - if (!($stat = self::url_stat($id,0))) + $vfs = new self(); + if (!($stat = $vfs->url_stat($id,0))) { if (self::LOG_LEVEL) error_log(__METHOD__."(".array2string($path_ids).",$ns) path '$id' not found!"); return false; diff --git a/api/src/Vfs/Sqlfs/Utils.php b/api/src/Vfs/Sqlfs/Utils.php index 65857a8bbe..f303328032 100644 --- a/api/src/Vfs/Sqlfs/Utils.php +++ b/api/src/Vfs/Sqlfs/Utils.php @@ -150,9 +150,10 @@ class Utils extends StreamWrapper ); $stmt = $delete_stmt = null; $msgs = array(); + $sqlfs = Vfs\Sqlfs(); foreach($dirs as $path => $id) { - if (!($stat = self::url_stat($path, STREAM_URL_STAT_LINK))) + if (!($stat = $sqlfs->url_stat($path, STREAM_URL_STAT_LINK))) { if ($check_only) { @@ -308,6 +309,7 @@ class Utils extends StreamWrapper { $lostnfound = null; $msgs = array(); + $sqlfs = Vfs\Sqlfs(); foreach(self::$pdo->query('SELECT fs.* FROM '.self::TABLE.' fs'. ' LEFT JOIN '.self::TABLE.' dir ON dir.fs_id=fs.fs_dir'. ' WHERE fs.fs_id > 1 AND dir.fs_id IS NULL') as $row) @@ -322,13 +324,13 @@ class Utils extends StreamWrapper if (!isset($lostnfound)) { // check if we already have /lost+found, create it if not - if (!($lostnfound = self::url_stat(self::LOST_N_FOUND, STREAM_URL_STAT_QUIET))) + if (!($lostnfound = $sqlfs->url_stat(self::LOST_N_FOUND, STREAM_URL_STAT_QUIET))) { Vfs::$is_root = true; if (!self::mkdir(self::LOST_N_FOUND, self::LOST_N_FOUND_MOD, 0) || !(!($admins = $GLOBALS['egw']->accounts->name2id(self::LOST_N_FOUND_GRP)) || self::chgrp(self::LOST_N_FOUND, $admins) && self::chmod(self::LOST_N_FOUND,self::LOST_N_FOUND_MOD)) || - !($lostnfound = self::url_stat(self::LOST_N_FOUND, STREAM_URL_STAT_QUIET))) + !($lostnfound = $sqlfs->url_stat(self::LOST_N_FOUND, STREAM_URL_STAT_QUIET))) { $msgs[] = lang("Can't create directory %1 to connect found unconnected nodes to it!",self::LOST_N_FOUND); } diff --git a/api/src/Vfs/StreamWrapper.php b/api/src/Vfs/StreamWrapper.php index ab9c1329fd..74624a90ca 100644 --- a/api/src/Vfs/StreamWrapper.php +++ b/api/src/Vfs/StreamWrapper.php @@ -157,11 +157,11 @@ class StreamWrapper implements StreamWrapperIface * @param array|boolean &$stat=null on return: stat of existing file or false for non-existing files * @return string|boolean false if the url cant be resolved, should not happen if fstab has a root entry */ - static function resolve_url_symlinks($_path,$file_exists=true,$resolve_last_symlink=true,&$stat=null) + function resolve_url_symlinks($_path,$file_exists=true,$resolve_last_symlink=true,&$stat=null) { $path = self::get_path($_path); - if (!($stat = self::url_stat($path,$resolve_last_symlink?0:STREAM_URL_STAT_LINK)) && !$file_exists) + if (!($stat = $this->url_stat($path,$resolve_last_symlink?0:STREAM_URL_STAT_LINK)) && !$file_exists) { $url = null; $stat = self::check_symlink_components($path,0,$url); @@ -316,7 +316,7 @@ class StreamWrapper implements StreamWrapperIface $this->opened_stream = null; $stat = null; - if (!($url = self::resolve_url_symlinks($path,$mode[0]=='r',true,$stat))) + if (!($url = $this->resolve_url_symlinks($path,$mode[0]=='r',true,$stat))) { return false; } @@ -489,9 +489,9 @@ class StreamWrapper implements StreamWrapperIface * @param string $path * @return boolean TRUE on success or FALSE on failure */ - static function unlink ( $path ) + function unlink ( $path ) { - if (!($url = self::resolve_url_symlinks($path,true,false))) // true,false file need to exist, but do not resolve last component + if (!($url = $this->resolve_url_symlinks($path,true,false))) // true,false file need to exist, but do not resolve last component { return false; } @@ -499,7 +499,7 @@ class StreamWrapper implements StreamWrapperIface { return false; } - $stat = self::url_stat($path, STREAM_URL_STAT_LINK); + $stat = $this->url_stat($path, STREAM_URL_STAT_LINK); self::symlinkCache_remove($path); $ok = unlink($url); @@ -529,10 +529,10 @@ class StreamWrapper implements StreamWrapperIface * @param string $path_to * @return boolean TRUE on success or FALSE on failure */ - static function rename ( $path_from, $path_to ) + function rename ( $path_from, $path_to ) { - if (!($url_from = self::resolve_url_symlinks($path_from,true,false)) || - !($url_to = self::resolve_url_symlinks($path_to,false))) + if (!($url_from = $this->resolve_url_symlinks($path_from,true,false)) || + !($url_to = $this->resolve_url_symlinks($path_to,false))) { return false; } @@ -547,7 +547,7 @@ class StreamWrapper implements StreamWrapperIface $ret = stream_copy_to_stream($from,$to) !== false; fclose($from); fclose($to); - if ($ret) self::unlink($path_from); + if ($ret) $this->unlink($path_from); } else { @@ -582,9 +582,9 @@ class StreamWrapper implements StreamWrapperIface * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE * @return boolean TRUE on success or FALSE on failure */ - static function mkdir ( $path, $mode, $options ) + function mkdir ( $path, $mode, $options ) { - if (!($url = self::resolve_url_symlinks($path,false))) // false = directory does not need to exists + if (!($url = $this->resolve_url_symlinks($path,false))) // false = directory does not need to exists { return false; } @@ -612,10 +612,10 @@ class StreamWrapper implements StreamWrapperIface * @param int $options Possible values include STREAM_REPORT_ERRORS. * @return boolean TRUE on success or FALSE on failure. */ - static function rmdir ( $path, $options ) + function rmdir ( $path, $options ) { unset($options); // not uses but required by function signature - if (!($url = self::resolve_url_symlinks($path))) + if (!($url = $this->resolve_url_symlinks($path))) { return false; } @@ -623,7 +623,7 @@ class StreamWrapper implements StreamWrapperIface { return false; } - $stat = self::url_stat($path, STREAM_URL_STAT_LINK); + $stat = $this->url_stat($path, STREAM_URL_STAT_LINK); self::symlinkCache_remove($path); $ok = rmdir($url); @@ -658,9 +658,10 @@ class StreamWrapper implements StreamWrapperIface $pathes = $params[$path_param_key]; $scheme2urls = array(); + $vfs = new Vfs\StreamWrapper(); foreach(is_array($pathes) ? $pathes : array($pathes) as $path) { - if (!($url = self::resolve_url_symlinks($path,false,false))) + if (!($url = $vfs->resolve_url_symlinks($path,false,false))) { return false; } @@ -815,7 +816,8 @@ class StreamWrapper implements StreamWrapperIface */ static function mime_content_type($path,$recheck=false) { - if (!($url = self::resolve_url_symlinks($path))) + $vfs = new self(); + if (!($url = $vfs->resolve_url_symlinks($path))) { return false; } @@ -827,7 +829,8 @@ class StreamWrapper implements StreamWrapperIface defined($class.'::STAT_RETURN_MIME_TYPE') && ($mime_attr = constant($class.'::STAT_RETURN_MIME_TYPE'))) { - $stat = call_user_func(array($class,'url_stat'),self::parse_url($url,PHP_URL_PATH),0); + $inst = new $class; + $stat = $inst->url_stat(self::parse_url($url,PHP_URL_PATH),0); if ($stat && $stat[$mime_attr]) { $mime = $stat[$mime_attr]; @@ -864,7 +867,7 @@ class StreamWrapper implements StreamWrapperIface $this->dir_url_params = array(); $this->extra_dir_ptr = 0; - if (!($this->opened_dir_url = self::resolve_url_symlinks($path))) + if (!($this->opened_dir_url = $this->resolve_url_symlinks($path))) { if (self::LOG_LEVEL > 0) error_log(__METHOD__."( $path,$options) resolve_url_symlinks() failed!"); return false; @@ -922,7 +925,7 @@ class StreamWrapper implements StreamWrapperIface * @param boolean $check_symlink_components =true check if path contains symlinks in path components other then the last one * @return array */ - static function url_stat ( $path, $flags, $try_create_home=false, $check_symlink_components=true, $check_symlink_depth=self::MAX_SYMLINK_DEPTH, $try_reconnect=true ) + function url_stat ( $path, $flags, $try_create_home=false, $check_symlink_components=true, $check_symlink_depth=self::MAX_SYMLINK_DEPTH, $try_reconnect=true ) { if (!($url = self::resolve_url($path,!($flags & STREAM_URL_STAT_LINK), $check_symlink_components))) { @@ -956,7 +959,7 @@ class StreamWrapper implements StreamWrapperIface $url = Vfs::PREFIX.$lpath; if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,$flags) symlif (substr($path,-1) == '/' && $path != '/') $path = substr($path,0,-1); // remove trailing slash eg. added by WebDAVink found and resolved to $url"); // try reading the stat of the link - if (($stat = self::url_stat($lpath, STREAM_URL_STAT_QUIET, false, true, $check_symlink_depth-1))) + if (($stat = $this->url_stat($lpath, STREAM_URL_STAT_QUIET, false, true, $check_symlink_depth-1))) { $stat_query = parse_url($stat['url'], PHP_URL_QUERY); if($u_query || $stat_query) @@ -982,7 +985,7 @@ class StreamWrapper implements StreamWrapperIface { // reconnect to db Vfs\Sqlfs\StreamWrapper::reconnect(); - return self::url_stat($path, $flags, $try_create_home, $check_symlink_components, $check_symlink_depth, false); + return $this->url_stat($path, $flags, $try_create_home, $check_symlink_components, $check_symlink_depth, false); } // if numer of tries is exceeded, re-throw exception throw $e; @@ -1000,7 +1003,7 @@ class StreamWrapper implements StreamWrapperIface ); call_user_func(array(__NAMESPACE__.'\\Hooks',$hook_data['location']),$hook_data); unset($hook_data); - $stat = self::url_stat($path,$flags,false); + $stat = $this->url_stat($path,$flags,false); } $query = parse_url($url, PHP_URL_QUERY); if (!$stat && $check_symlink_components) // check if there's a symlink somewhere inbetween the path @@ -1043,7 +1046,7 @@ class StreamWrapper implements StreamWrapperIface * @param string &$url=null already resolved path * @return array|boolean stat array or false if not found */ - static private function check_symlink_components($path,$flags=0,&$url=null) + private function check_symlink_components($path,$flags=0,&$url=null) { if (is_null($url) && !($url = self::resolve_url($path))) { @@ -1055,7 +1058,7 @@ class StreamWrapper implements StreamWrapperIface while (($rel_path = Vfs::basename($url).($rel_path ? '/'.$rel_path : '')) && ($url = Vfs::dirname($url))) { - if (($stat = self::url_stat($url,0,false,false))) + if (($stat = $this->url_stat($url,0,false,false))) { if (is_link($url) && ($lpath = self::readlink($url))) { @@ -1068,7 +1071,7 @@ class StreamWrapper implements StreamWrapperIface //self::symlinkCache_add($path,Vfs::PREFIX.$lpath); $url = Vfs::PREFIX.Vfs::concat($lpath,$rel_path); if (self::LOG_LEVEL > 1) error_log("$log --> lpath='$lpath', url='$url'"); - return self::url_stat($url,$flags); + return $this->url_stat($url,$flags); } $url = Vfs::concat($url,$rel_path); if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning null"); diff --git a/api/src/Vfs/StreamWrapperIface.php b/api/src/Vfs/StreamWrapperIface.php index e9ac4e05b9..0003086127 100644 --- a/api/src/Vfs/StreamWrapperIface.php +++ b/api/src/Vfs/StreamWrapperIface.php @@ -143,7 +143,7 @@ interface StreamWrapperIface * @param string $path * @return boolean TRUE on success or FALSE on failure */ - static function unlink ( $path ); + function unlink ( $path ); /** * This method is called in response to rename() calls on URL paths associated with the wrapper. @@ -157,7 +157,7 @@ interface StreamWrapperIface * @param string $path_to * @return boolean TRUE on success or FALSE on failure */ - static function rename ( $path_from, $path_to ); + function rename ( $path_from, $path_to ); /** * This method is called in response to mkdir() calls on URL paths associated with the wrapper. @@ -170,7 +170,7 @@ interface StreamWrapperIface * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE * @return boolean TRUE on success or FALSE on failure */ - static function mkdir ( $path, $mode, $options ); + function mkdir ( $path, $mode, $options ); /** * This method is called in response to rmdir() calls on URL paths associated with the wrapper. @@ -182,7 +182,7 @@ interface StreamWrapperIface * @param int $options Possible values include STREAM_REPORT_ERRORS. * @return boolean TRUE on success or FALSE on failure. */ - static function rmdir ( $path, $options ); + function rmdir ( $path, $options ); /** * This method is called immediately when your stream object is created for examining directory contents with opendir(). @@ -218,7 +218,7 @@ interface StreamWrapperIface * stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper! * @return array */ - static function url_stat ( $path, $flags ); + function url_stat ( $path, $flags ); /** * This method is called in response to readdir().