diff options
Diffstat (limited to 'lib/filesystem.php')
-rw-r--r-- | lib/filesystem.php | 103 |
1 files changed, 27 insertions, 76 deletions
diff --git a/lib/filesystem.php b/lib/filesystem.php index 44401260c5e..8765775dc29 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -42,39 +42,11 @@ * * the &run parameter can be set to false to prevent the operation from occuring */ + class OC_Filesystem{ static private $storages=array(); static private $mounts=array(); static private $fakeRoot=''; - static private $storageTypes=array(); - - - /** - * register a storage type - * @param string type - * @param string classname - * @param array arguments an associative array in the form of name=>type (eg array('datadir'=>'string')) - */ - static public function registerStorageType($type,$classname,$arguments){ - self::$storageTypes[$type]=array('type'=>$type,'classname'=>$classname,'arguments'=>$arguments); - } - - /** - * check if the filesystem supports a specific storagetype - * @param string type - * @return bool - */ - static public function hasStorageType($type){ - return isset(self::$storageTypes[$type]); - } - - /** - * get the list of names of storagetypes that the filesystem supports - * @return array - */ - static public function getStorageTypeNames(){ - return array_keys(self::$storageTypes); - } /** * tear down the filesystem, removing all storage providers @@ -92,13 +64,9 @@ class OC_Filesystem{ * @param array arguments * @return OC_Filestorage */ - static private function createStorage($type,$arguments){ - if(!self::hasStorageType($type)){ - return false; - } - $className=self::$storageTypes[$type]['classname']; - if(class_exists($className)){ - return new $className($arguments); + static private function createStorage($class,$arguments){ + if(class_exists($class)){ + return new $class($arguments); }else{ return false; } @@ -117,6 +85,14 @@ class OC_Filesystem{ } self::$fakeRoot=$fakeRoot; } + + /** + * get the fake root + * @return string + */ + static public function getRoot(){ + return self::$fakeRoot; + } /** * get the part of the path relative to the mountpoint of the storage it's stored in @@ -135,11 +111,11 @@ class OC_Filesystem{ * @param OC_Filestorage storage * @param string mountpoint */ - static public function mount($type,$arguments,$mountpoint){ + static public function mount($class,$arguments,$mountpoint){ if(substr($mountpoint,0,1)!=='/'){ $mountpoint='/'.$mountpoint; } - self::$mounts[$mountpoint]=array('type'=>$type,'arguments'=>$arguments); + self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments); } /** @@ -152,7 +128,7 @@ class OC_Filesystem{ if($mountpoint){ if(!isset(self::$storages[$mountpoint])){ $mount=self::$mounts[$mountpoint]; - self::$storages[$mountpoint]=self::createStorage($mount['type'],$mount['arguments']); + self::$storages[$mountpoint]=self::createStorage($mount['class'],$mount['arguments']); } return self::$storages[$mountpoint]; } @@ -218,7 +194,9 @@ class OC_Filesystem{ } return true; } - + /** + * following functions are equivilent to their php buildin equivilents for arguments/return values. + */ static public function mkdir($path){ return self::basicOperation('mkdir',$path,array('create','write')); } @@ -270,9 +248,6 @@ class OC_Filesystem{ static public function filemtime($path){ return self::basicOperation('filemtime',$path); } - static public function fileatime($path){ - return self::basicOperation('fileatime',$path); - } static public function file_get_contents($path){ return self::basicOperation('file_get_contents',$path,array('read')); } @@ -384,26 +359,6 @@ class OC_Filesystem{ } } } - static public function fromUploadedFile($tmpFile,$path){ - if(OC_FileProxy::runPreProxies('fromUploadedFile',$tmpFile,$path) and self::isValidPath($path) and $storage=self::getStorage($path)){ - $run=true; - $exists=self::file_exists($path); - if(!$exists){ - OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run)); - } - if($run){ - OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run)); - } - if($run){ - $result=$storage->fromUploadedFile($tmpFile,self::getInternalPath($path)); - if(!$exists){ - OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path)); - } - OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path)); - return $result; - } - } - } static public function getMimeType($path){ return self::basicOperation('getMimeType',$path); } @@ -419,15 +374,13 @@ class OC_Filesystem{ $files=array(); $fakeRoot=self::$fakeRoot; $fakeRootLength=strlen($fakeRoot); - foreach(self::$storages as $mountpoint=>$storage){ - $results=$storage->search($query); - if(is_array($results)){ - foreach($results as $result){ - $file=str_replace('//','/',$mountpoint.$result); - if(substr($file,0,$fakeRootLength)==$fakeRoot){ - $file=substr($file,$fakeRootLength); - $files[]=$file; - } + $results=OC_FileCache::search($query); + if(is_array($results)){ + foreach($results as $result){ + $file=str_replace('//','/',$mountpoint.$result); + if(substr($file,0,$fakeRootLength)==$fakeRoot){ + $file=substr($file,$fakeRootLength); + $files[]=$file; } } } @@ -435,10 +388,6 @@ class OC_Filesystem{ } - static public function update_session_file_hash($sessionname,$sessionvalue){ - $_SESSION[$sessionname] = $sessionvalue; - } - /** * abstraction for running most basic operations * @param string $operation @@ -476,3 +425,5 @@ class OC_Filesystem{ return null; } } + +require_once('filecache.php'); |