Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/filesystemview.php')
-rw-r--r--lib/filesystemview.php58
1 files changed, 51 insertions, 7 deletions
diff --git a/lib/filesystemview.php b/lib/filesystemview.php
index c8df59cf827..58657671b98 100644
--- a/lib/filesystemview.php
+++ b/lib/filesystemview.php
@@ -40,6 +40,8 @@
class OC_FilesystemView {
private $fakeRoot='';
+ private $internal_path_cache=array();
+ private $storage_cache=array();
public function __construct($root){
$this->fakeRoot=$root;
@@ -49,7 +51,7 @@ class OC_FilesystemView {
if(!$path){
$path='/';
}
- if(substr($path,0,1)!=='/'){
+ if($path[0]!=='/'){
$path='/'.$path;
}
return $this->fakeRoot.$path;
@@ -84,15 +86,38 @@ class OC_FilesystemView {
* @return bool
*/
public function getInternalPath($path){
- return OC_Filesystem::getInternalPath($this->getAbsolutePath($path));
+ if (!isset($this->internal_path_cache[$path])) {
+ $this->internal_path_cache[$path] = OC_Filesystem::getInternalPath($this->getAbsolutePath($path));
+ }
+ return $this->internal_path_cache[$path];
+ }
+
+ /**
+ * get path relative to the root of the view
+ * @param string path
+ * @return string
+ */
+ public function getRelativePath($path){
+ if($this->fakeRoot==''){
+ return $path;
+ }
+ if(strpos($path,$this->fakeRoot)!==0){
+ return null;
+ }else{
+ return substr($path,strlen($this->fakeRoot));
+ }
}
+
/**
* get the storage object for a path
* @param string path
* @return OC_Filestorage
*/
public function getStorage($path){
- return OC_Filesystem::getStorage($this->getAbsolutePath($path));
+ if (!isset($this->storage_cache[$path])) {
+ $this->storage_cache[$path] = OC_Filesystem::getStorage($this->getAbsolutePath($path));
+ }
+ return $this->storage_cache[$path];
}
/**
@@ -224,7 +249,14 @@ class OC_FilesystemView {
return $this->basicOperation('unlink',$path,array('delete'));
}
public function rename($path1,$path2){
- if(OC_FileProxy::runPreProxies('rename',$path1,$path2) and OC_Filesystem::isValidPath($path2)){
+ $absolutePath1=$this->getAbsolutePath($path1);
+ $absolutePath2=$this->getAbsolutePath($path2);
+ if(OC_FileProxy::runPreProxies('rename',$absolutePath1,$absolutePath2) and OC_Filesystem::isValidPath($path2)){
+ $path1=$this->getRelativePath($absolutePath1);
+ $path2=$this->getRelativePath($absolutePath2);
+ if($path1==null or $path2==null){
+ return false;
+ }
$run=true;
OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename, array( OC_Filesystem::signal_param_oldpath => $path1 , OC_Filesystem::signal_param_newpath=>$path2, OC_Filesystem::signal_param_run => &$run));
if($run){
@@ -248,7 +280,14 @@ class OC_FilesystemView {
}
}
public function copy($path1,$path2){
- if(OC_FileProxy::runPreProxies('copy',$path1,$path2) and $this->is_readable($path1) and OC_Filesystem::isValidPath($path2)){
+ $absolutePath1=$this->getAbsolutePath($path1);
+ $absolutePath2=$this->getAbsolutePath($path2);
+ if(OC_FileProxy::runPreProxies('copy',$absolutePath1,$absolutePath2) and OC_Filesystem::isValidPath($path2)){
+ $path1=$this->getRelativePath($absolutePath1);
+ $path2=$this->getRelativePath($absolutePath2);
+ if($path1==null or $path2==null){
+ return false;
+ }
$run=true;
OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_copy, array( OC_Filesystem::signal_param_oldpath => $path1 , OC_Filesystem::signal_param_newpath=>$path2, OC_Filesystem::signal_param_run => &$run));
$exists=$this->file_exists($path2);
@@ -367,7 +406,12 @@ class OC_FilesystemView {
* OC_Filestorage for delegation to a storage backend for execution
*/
private function basicOperation($operation,$path,$hooks=array(),$extraParam=null){
- if(OC_FileProxy::runPreProxies($operation,$path, $extraParam) and OC_Filesystem::isValidPath($path)){
+ $absolutePath=$this->getAbsolutePath($path);
+ if(OC_FileProxy::runPreProxies($operation,$absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)){
+ $path=$this->getRelativePath($absolutePath);
+ if($path==null){
+ return false;
+ }
$internalPath=$this->getInternalPath($path);
$run=true;
if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()){
@@ -385,7 +429,7 @@ class OC_FilesystemView {
}else{
$result=$storage->$operation($internalPath);
}
- $result=OC_FileProxy::runPostProxies($operation,$path,$result);
+ $result=OC_FileProxy::runPostProxies($operation,$this->getAbsolutePath($path),$result);
if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()){
if($operation!='fopen'){//no post hooks for fopen, the file stream is still open
foreach($hooks as $hook){