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)

This commit is contained in:
Ralf Becker 2016-07-19 11:59:16 +02:00
parent f4acec1b82
commit b65d87bc68
9 changed files with 99 additions and 76 deletions

View File

@ -1300,7 +1300,7 @@ class Link extends Link\Storage
if (!is_array($fileinfo)) if (!is_array($fileinfo))
{ {
$url = Vfs\Sqlfs\StreamWrapper::id2path($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; return false;
} }

View File

@ -242,7 +242,8 @@ class Vfs extends Vfs\StreamWrapper
{ {
throw new Exception\AssertionFailed("File '$path' is not an absolute path!"); 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 $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!"); 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 $stat = array_slice($stat,13); // remove numerical indices 0-12
} }
@ -683,7 +685,8 @@ class Vfs extends Vfs\StreamWrapper
} }
else 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) if (!$stat)
{ {
@ -802,11 +805,12 @@ class Vfs extends Vfs\StreamWrapper
{ {
$url = self::PREFIX . $url; $url = self::PREFIX . $url;
} }
$vfs = new Vfs\StreamWrapper();
if (is_dir($url) && !is_link($url)) 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); 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! 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 // query stat array, if not given
if (is_null($stat)) 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)"); //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) 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 return $stat['uid'] == self::$user || // user is the owner
self::$is_root || // class runs with root rights self::$is_root || // class runs with root rights
!$stat['uid'] && $stat['gid'] && self::$is_admin; // group directory and user is an eGW admin !$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)) if (self::is_dir($dst))
{ {
$vfs = new Vfs\StreamWrapper();
foreach($src as $file) foreach($src as $file)
{ {
$target = self::concat($dst, self::basename($file)); $target = self::concat($dst, self::basename($file));
if ($file != $target && self::rename($file, $target)) if ($file != $target && $vfs->rename($file, $target))
{ {
$moved[] = $file; $moved[] = $file;
} }

View File

@ -66,7 +66,7 @@ class File extends DAV\FS\File
*/ */
function getETag() 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'].'"'; return '"'.$stat['ino'].':'.$stat['mtime'].':'.$stat['size'].'"';
} }

View File

@ -306,7 +306,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface
* @param string $url * @param string $url
* @return boolean TRUE on success or FALSE on failure * @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)); $path = Vfs::decodePath(Vfs::parse_url($url,PHP_URL_PATH));
@ -331,7 +331,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface
* @param string $url_to * @param string $url_to
* @return boolean TRUE on success or FALSE on failure * @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); $from = Vfs::parse_url($url_from);
$to = Vfs::parse_url($url_to); $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 * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE
* @return boolean TRUE on success or FALSE on failure * @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 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. * @param int $options Possible values include STREAM_REPORT_ERRORS.
* @return boolean TRUE on success or FALSE on failure. * @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 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! * stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper!
* @return array * @return array
*/ */
static function url_stat ( $url, $flags ) function url_stat ( $url, $flags )
{ {
$parts = Vfs::parse_url($url); $parts = Vfs::parse_url($url);
$path = Vfs::decodePath($parts['path']); $path = Vfs::decodePath($parts['path']);

View File

@ -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! * stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper!
* @return array * @return array
*/ */
static function url_stat ( $url, $flags ) function url_stat ( $url, $flags )
{ {
$eacl_check=self::check_extended_acl($url,Vfs::READABLE); $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! * @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 * @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 unset($mode); // not used, but required by function signature

View File

@ -543,7 +543,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface
* @param string $url * @param string $url
* @return boolean TRUE on success or FALSE on failure * @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)"); 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)) if (!isset($parent_stat))
{ {
$parent_stat = !($dir = Vfs::dirname($path)) ? false : $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)) !$dir || !Vfs::check_access($dir, Vfs::WRITABLE, $parent_stat))
{ {
self::_remove_password($url); self::_remove_password($url);
@ -599,7 +599,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface
* @param string $url_to * @param string $url_to
* @return boolean TRUE on success or FALSE on failure * @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)"); 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 * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE
* @return boolean TRUE on success or FALSE on failure * @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__."($url,$mode,$options)");
if (self::LOG_LEVEL > 1) error_log(__METHOD__." called from:".function_backtrace()); if (self::LOG_LEVEL > 1) error_log(__METHOD__." called from:".function_backtrace());
$path = Vfs::parse_url($url,PHP_URL_PATH); $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); self::_remove_password($url);
if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) already exist!"); 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; return false;
} }
if (($query = Vfs::parse_url($url,PHP_URL_QUERY))) $parent_path .= '?'.$query; 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, // 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 // if yes call ourself recursive with the parent directory
@ -731,7 +731,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface
{ {
return false; 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)) 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. * @param int $options Possible values include STREAM_REPORT_ERRORS.
* @return boolean TRUE on success or FALSE on failure. * @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)"); if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
$path = Vfs::parse_url($url,PHP_URL_PATH); $path = Vfs::parse_url($url,PHP_URL_PATH);
if (!($parent = Vfs::dirname($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))) !Vfs::check_access($parent, Vfs::WRITABLE, static::url_stat($parent,0)))
{ {
self::_remove_password($url); 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); $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 // file does not exist --> create an empty one
if (!($f = fopen(self::SCHEME.'://default'.$path,'w')) || !fclose($f)) 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 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]); 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'); $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); $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!"); 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); 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); $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!"); 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); 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); $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!"); 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); 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); $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 $stat['mime'] != self::DIR_MIME_TYPE || // no dir
!Vfs::check_access($url,Vfs::EXECUTABLE|Vfs::READABLE,$stat)) // no access !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!) * @param boolean $eacl_access =null allows extending classes to pass the value of their check_extended_acl() method (no lsb!)
* @return array * @return array
*/ */
static function url_stat ( $url, $flags, $eacl_access=null ) function url_stat ( $url, $flags, $eacl_access=null )
{ {
static $max_subquery_depth=null; static $max_subquery_depth=null;
if (is_null($max_subquery_depth)) 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"); error_log(__METHOD__."() decremented max_subquery_depth to $max_subquery_depth");
Api\Config::save_value('max_subquery_depth', $max_subquery_depth, 'phpgwapi'); Api\Config::save_value('max_subquery_depth', $max_subquery_depth, 'phpgwapi');
if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) $GLOBALS['egw']->invalidate_session_cache(); 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; self::$stat_cache[$path] = $info;
@ -1284,7 +1288,8 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface
*/ */
static function readlink($path) 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"); 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::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!"); if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') $link exists, returning false!");
return false; // $link already exists return false; // $link already exists
@ -1422,7 +1428,8 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface
} }
if (is_null($fs_id)) 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!"); if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) no such file or directory!");
return false; // $path not found 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 (self::LOG_LEVEL > 1) error_log(__METHOD__."(".array2string($path).','.array2string($props));
if (!is_numeric($path)) if (!is_numeric($path))
{ {
if (!($stat = self::url_stat($path,0))) if (!($stat = $vfs->url_stat($path,0)))
{ {
return false; return false;
} }
@ -1807,7 +1814,8 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface
{ {
if (!is_numeric($id)) 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!"); if (self::LOG_LEVEL) error_log(__METHOD__."(".array2string($path_ids).",$ns) path '$id' not found!");
return false; return false;

View File

@ -150,9 +150,10 @@ class Utils extends StreamWrapper
); );
$stmt = $delete_stmt = null; $stmt = $delete_stmt = null;
$msgs = array(); $msgs = array();
$sqlfs = Vfs\Sqlfs();
foreach($dirs as $path => $id) 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) if ($check_only)
{ {
@ -308,6 +309,7 @@ class Utils extends StreamWrapper
{ {
$lostnfound = null; $lostnfound = null;
$msgs = array(); $msgs = array();
$sqlfs = Vfs\Sqlfs();
foreach(self::$pdo->query('SELECT fs.* FROM '.self::TABLE.' fs'. foreach(self::$pdo->query('SELECT fs.* FROM '.self::TABLE.' fs'.
' LEFT JOIN '.self::TABLE.' dir ON dir.fs_id=fs.fs_dir'. ' 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) ' WHERE fs.fs_id > 1 AND dir.fs_id IS NULL') as $row)
@ -322,13 +324,13 @@ class Utils extends StreamWrapper
if (!isset($lostnfound)) if (!isset($lostnfound))
{ {
// check if we already have /lost+found, create it if not // 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; Vfs::$is_root = true;
if (!self::mkdir(self::LOST_N_FOUND, self::LOST_N_FOUND_MOD, 0) || if (!self::mkdir(self::LOST_N_FOUND, self::LOST_N_FOUND_MOD, 0) ||
!(!($admins = $GLOBALS['egw']->accounts->name2id(self::LOST_N_FOUND_GRP)) || !(!($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)) || 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); $msgs[] = lang("Can't create directory %1 to connect found unconnected nodes to it!",self::LOST_N_FOUND);
} }

View File

@ -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 * @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 * @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); $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; $url = null;
$stat = self::check_symlink_components($path,0,$url); $stat = self::check_symlink_components($path,0,$url);
@ -316,7 +316,7 @@ class StreamWrapper implements StreamWrapperIface
$this->opened_stream = null; $this->opened_stream = null;
$stat = 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; return false;
} }
@ -489,9 +489,9 @@ class StreamWrapper implements StreamWrapperIface
* @param string $path * @param string $path
* @return boolean TRUE on success or FALSE on failure * @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; return false;
} }
@ -499,7 +499,7 @@ class StreamWrapper implements StreamWrapperIface
{ {
return false; return false;
} }
$stat = self::url_stat($path, STREAM_URL_STAT_LINK); $stat = $this->url_stat($path, STREAM_URL_STAT_LINK);
self::symlinkCache_remove($path); self::symlinkCache_remove($path);
$ok = unlink($url); $ok = unlink($url);
@ -529,10 +529,10 @@ class StreamWrapper implements StreamWrapperIface
* @param string $path_to * @param string $path_to
* @return boolean TRUE on success or FALSE on failure * @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)) || if (!($url_from = $this->resolve_url_symlinks($path_from,true,false)) ||
!($url_to = self::resolve_url_symlinks($path_to,false))) !($url_to = $this->resolve_url_symlinks($path_to,false)))
{ {
return false; return false;
} }
@ -547,7 +547,7 @@ class StreamWrapper implements StreamWrapperIface
$ret = stream_copy_to_stream($from,$to) !== false; $ret = stream_copy_to_stream($from,$to) !== false;
fclose($from); fclose($from);
fclose($to); fclose($to);
if ($ret) self::unlink($path_from); if ($ret) $this->unlink($path_from);
} }
else else
{ {
@ -582,9 +582,9 @@ class StreamWrapper implements StreamWrapperIface
* @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE
* @return boolean TRUE on success or FALSE on failure * @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; return false;
} }
@ -612,10 +612,10 @@ class StreamWrapper implements StreamWrapperIface
* @param int $options Possible values include STREAM_REPORT_ERRORS. * @param int $options Possible values include STREAM_REPORT_ERRORS.
* @return boolean TRUE on success or FALSE on failure. * @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 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; return false;
} }
@ -623,7 +623,7 @@ class StreamWrapper implements StreamWrapperIface
{ {
return false; return false;
} }
$stat = self::url_stat($path, STREAM_URL_STAT_LINK); $stat = $this->url_stat($path, STREAM_URL_STAT_LINK);
self::symlinkCache_remove($path); self::symlinkCache_remove($path);
$ok = rmdir($url); $ok = rmdir($url);
@ -658,9 +658,10 @@ class StreamWrapper implements StreamWrapperIface
$pathes = $params[$path_param_key]; $pathes = $params[$path_param_key];
$scheme2urls = array(); $scheme2urls = array();
$vfs = new Vfs\StreamWrapper();
foreach(is_array($pathes) ? $pathes : array($pathes) as $path) 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; return false;
} }
@ -815,7 +816,8 @@ class StreamWrapper implements StreamWrapperIface
*/ */
static function mime_content_type($path,$recheck=false) 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; return false;
} }
@ -827,7 +829,8 @@ class StreamWrapper implements StreamWrapperIface
defined($class.'::STAT_RETURN_MIME_TYPE') && defined($class.'::STAT_RETURN_MIME_TYPE') &&
($mime_attr = constant($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]) if ($stat && $stat[$mime_attr])
{ {
$mime = $stat[$mime_attr]; $mime = $stat[$mime_attr];
@ -864,7 +867,7 @@ class StreamWrapper implements StreamWrapperIface
$this->dir_url_params = array(); $this->dir_url_params = array();
$this->extra_dir_ptr = 0; $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!"); if (self::LOG_LEVEL > 0) error_log(__METHOD__."( $path,$options) resolve_url_symlinks() failed!");
return false; 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 * @param boolean $check_symlink_components =true check if path contains symlinks in path components other then the last one
* @return array * @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))) 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; $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"); 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 // 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); $stat_query = parse_url($stat['url'], PHP_URL_QUERY);
if($u_query || $stat_query) if($u_query || $stat_query)
@ -982,7 +985,7 @@ class StreamWrapper implements StreamWrapperIface
{ {
// reconnect to db // reconnect to db
Vfs\Sqlfs\StreamWrapper::reconnect(); 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 // if numer of tries is exceeded, re-throw exception
throw $e; throw $e;
@ -1000,7 +1003,7 @@ class StreamWrapper implements StreamWrapperIface
); );
call_user_func(array(__NAMESPACE__.'\\Hooks',$hook_data['location']),$hook_data); call_user_func(array(__NAMESPACE__.'\\Hooks',$hook_data['location']),$hook_data);
unset($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); $query = parse_url($url, PHP_URL_QUERY);
if (!$stat && $check_symlink_components) // check if there's a symlink somewhere inbetween the path 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 * @param string &$url=null already resolved path
* @return array|boolean stat array or false if not found * @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))) 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 : '')) && while (($rel_path = Vfs::basename($url).($rel_path ? '/'.$rel_path : '')) &&
($url = Vfs::dirname($url))) ($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))) if (is_link($url) && ($lpath = self::readlink($url)))
{ {
@ -1068,7 +1071,7 @@ class StreamWrapper implements StreamWrapperIface
//self::symlinkCache_add($path,Vfs::PREFIX.$lpath); //self::symlinkCache_add($path,Vfs::PREFIX.$lpath);
$url = Vfs::PREFIX.Vfs::concat($lpath,$rel_path); $url = Vfs::PREFIX.Vfs::concat($lpath,$rel_path);
if (self::LOG_LEVEL > 1) error_log("$log --> lpath='$lpath', url='$url'"); 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); $url = Vfs::concat($url,$rel_path);
if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning null"); if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning null");

View File

@ -143,7 +143,7 @@ interface StreamWrapperIface
* @param string $path * @param string $path
* @return boolean TRUE on success or FALSE on failure * @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. * 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 * @param string $path_to
* @return boolean TRUE on success or FALSE on failure * @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. * 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 * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE
* @return boolean TRUE on success or FALSE on failure * @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. * 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. * @param int $options Possible values include STREAM_REPORT_ERRORS.
* @return boolean TRUE on success or FALSE on failure. * @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(). * 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! * stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper!
* @return array * @return array
*/ */
static function url_stat ( $path, $flags ); function url_stat ( $path, $flags );
/** /**
* This method is called in response to readdir(). * This method is called in response to readdir().