summaryrefslogtreecommitdiffstats
path: root/lib/filesystem.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-01-16 03:06:11 +0100
committerRobin Appelman <icewind@owncloud.com>2012-01-16 03:06:11 +0100
commit96e2f15d8a6eee83e30bdf77ef3582f0c26b52e0 (patch)
tree9df43704cb7e580d328d6780561a0ec146003e7b /lib/filesystem.php
parentccc43f0ea02a048583fff715f00cda0280124586 (diff)
parentb0dbca0cc7f2d07dbf01c54861b932d8dc9fe2df (diff)
downloadnextcloud-server-96e2f15d8a6eee83e30bdf77ef3582f0c26b52e0.tar.gz
nextcloud-server-96e2f15d8a6eee83e30bdf77ef3582f0c26b52e0.zip
merge master into filesystem
Diffstat (limited to 'lib/filesystem.php')
-rw-r--r--lib/filesystem.php142
1 files changed, 126 insertions, 16 deletions
diff --git a/lib/filesystem.php b/lib/filesystem.php
index 8765775dc29..6568a07a59c 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -47,6 +47,93 @@ class OC_Filesystem{
static private $storages=array();
static private $mounts=array();
static private $fakeRoot='';
+ static private $storageTypes=array();
+
+ /**
+ * classname which used for hooks handling
+ * used as signalclass in OC_Hooks::emit()
+ */
+ const CLASSNAME = 'OC_Filesystem';
+
+ /**
+ * signalname emited before file renaming
+ * @param oldpath
+ * @param newpath
+ */
+ const signal_rename = 'rename';
+
+ /**
+ * signal emited after file renaming
+ * @param oldpath
+ * @param newpath
+ */
+ const signal_post_rename = 'post_rename';
+
+ /**
+ * signal emited before file/dir creation
+ * @param path
+ * @param run changing this flag to false in hook handler will cancel event
+ */
+ const signal_create = 'create';
+
+ /**
+ * signal emited after file/dir creation
+ * @param path
+ * @param run changing this flag to false in hook handler will cancel event
+ */
+ const signal_post_create = 'post_create';
+
+ /**
+ * signal emits before file/dir copy
+ * @param oldpath
+ * @param newpath
+ * @param run changing this flag to false in hook handler will cancel event
+ */
+ const signal_copy = 'copy';
+
+ /**
+ * signal emits after file/dir copy
+ * @param oldpath
+ * @param newpath
+ */
+ const signal_post_copy = 'post_copy';
+
+ /**
+ * signal emits before file/dir save
+ * @param path
+ * @param run changing this flag to false in hook handler will cancel event
+ */
+ const signal_write = 'write';
+
+ /**
+ * signal emits after file/dir save
+ * @param path
+ */
+ const signal_post_write = 'post_write';
+
+ /**
+ * signal emits when reading file/dir
+ * @param path
+ */
+ const signal_read = 'read';
+
+ /**
+ * signal emits when removing file/dir
+ * @param path
+ */
+ const signal_delete = 'delete';
+
+ /**
+ * parameters definitions for signals
+ */
+ const signal_param_path = 'path';
+ const signal_param_oldpath = 'oldpath';
+ const signal_param_newpath = 'newpath';
+
+ /**
+ * run - changing this flag to false in hook handler will cancel event
+ */
+ const signal_param_run = 'run';
/**
* tear down the filesystem, removing all storage providers
@@ -260,7 +347,7 @@ class OC_Filesystem{
static public function rename($path1,$path2){
if(OC_FileProxy::runPreProxies('rename',$path1,$path2) and self::is_writeable($path1) and self::isValidPath($path2)){
$run=true;
- OC_Hook::emit( 'OC_Filesystem', 'rename', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_rename, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2, self::signal_param_run => &$run));
if($run){
$mp1=self::getMountPoint($path1);
$mp2=self::getMountPoint($path2);
@@ -273,7 +360,7 @@ class OC_Filesystem{
$result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2));
$storage1->unlink(self::getInternalPath($path1));
}
- OC_Hook::emit( 'OC_Filesystem', 'post_rename', array( 'oldpath' => $path1, 'newpath'=>$path2));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_rename, array( self::signal_param_oldpath => $path1, self::signal_param_newpath=>$path2));
return $result;
}
}
@@ -281,13 +368,13 @@ class OC_Filesystem{
static public function copy($path1,$path2){
if(OC_FileProxy::runPreProxies('copy',$path1,$path2) and self::is_readable($path1) and self::isValidPath($path2)){
$run=true;
- OC_Hook::emit( 'OC_Filesystem', 'copy', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_copy, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2, self::signal_param_run => &$run));
$exists=self::file_exists($path2);
if($run and !$exists){
- OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path2, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path2, self::signal_param_run => &$run));
}
if($run){
- OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path2, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path2, self::signal_param_run => &$run));
}
if($run){
$mp1=self::getMountPoint($path1);
@@ -300,11 +387,11 @@ class OC_Filesystem{
$tmpFile=$storage1->toTmpFile(self::getInternalPath($path1));
$result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2));
}
- OC_Hook::emit( 'OC_Filesystem', 'post_copy', array( 'oldpath' => $path1 ,'newpath'=>$path2));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_copy, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2));
if(!$exists){
- OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path2));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path2));
}
- OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path2));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path2));
return $result;
}
}
@@ -335,7 +422,7 @@ class OC_Filesystem{
}
static public function toTmpFile($path){
if(OC_FileProxy::runPreProxies('toTmpFile',$path) and self::isValidPath($path) and $storage=self::getStorage($path)){
- OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, self::signal_read, array( self::signal_param_path => $path));
return $storage->toTmpFile(self::getInternalPath($path));
}
}
@@ -344,21 +431,44 @@ class OC_Filesystem{
$run=true;
$exists=self::file_exists($path);
if(!$exists){
- OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path, self::signal_param_run => &$run));
}
if($run){
- OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path, self::signal_param_run => &$run));
}
if($run){
$result=$storage->fromTmpFile($tmpFile,self::getInternalPath($path));
if(!$exists){
- OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path));
+ }
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path));
+ return $result;
+ }
+ }
+ }
+<<<<<<< HEAD
+=======
+ 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( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path, self::signal_param_run => &$run));
+ }
+ if($run){
+ OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path, self::signal_param_run => &$run));
+ }
+ if($run){
+ $result=$storage->fromUploadedFile($tmpFile,self::getInternalPath($path));
+ if(!$exists){
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path));
}
- OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path));
return $result;
}
}
}
+>>>>>>> master
static public function getMimeType($path){
return self::basicOperation('getMimeType',$path);
}
@@ -402,9 +512,9 @@ class OC_Filesystem{
$run=true;
foreach($hooks as $hook){
if($hook!='read'){
- OC_Hook::emit( 'OC_Filesystem', $hook, array( 'path' => $path, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, $hook, array( self::signal_param_path => $path, self::signal_param_run => &$run));
}else{
- OC_Hook::emit( 'OC_Filesystem', $hook, array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, $hook, array( self::signal_param_path => $path));
}
}
if($run){
@@ -416,7 +526,7 @@ class OC_Filesystem{
$result=OC_FileProxy::runPostProxies($operation,$path,$result);
foreach($hooks as $hook){
if($hook!='read'){
- OC_Hook::emit( 'OC_Filesystem', 'post_'.$hook, array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, 'post_'.$hook, array( self::signal_param_path => $path));
}
}
return $result;