summaryrefslogtreecommitdiffstats
path: root/lib/filestorage.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/filestorage.php')
-rw-r--r--lib/filestorage.php56
1 files changed, 33 insertions, 23 deletions
diff --git a/lib/filestorage.php b/lib/filestorage.php
index c20d6d7b3e0..576a6dbdf34 100644
--- a/lib/filestorage.php
+++ b/lib/filestorage.php
@@ -24,11 +24,11 @@
* Privde a common interface to all different storage options
*
* Hooks provided:
- * read(path)
- * write(path)
- * create(path)
- * delete(path)
- * rename(oldpath,newpath)
+ * read(storage,path)
+ * write(storage,path)
+ * create(storage,path) (when a file is created both, write and create will be emited)
+ * delete(storage,path)
+ * rename(storage,oldpath,newpath)
*/
class OC_FILESTORAGE{
public function __construct($parameters){}
@@ -85,14 +85,14 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
public function rmdir($path){
if($return=rmdir($this->datadir.$path)){
- OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $path));
$this->clearFolderSizeCache($path);
}
return $return;
}
public function opendir($path){
if($return=opendir($this->datadir.$path)){
- OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path));
}
return $return;
}
@@ -130,7 +130,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
public function readfile($path){
if($return=readfile($this->datadir.$path)){
- OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path));
}
return $return;
}
@@ -145,26 +145,29 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
public function file_get_contents($path){
if($return=file_get_contents($this->datadir.$path)){
- OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path));
}
return $return;
}
public function file_put_contents($path,$data){
+ if(!$this->file_exists($path)){
+ OC_HOOK::emit( 'OC_FILESTORAGE', 'create', array( 'storage'=>$this, 'path' => $path));
+ }
if($return=file_put_contents($this->datadir.$path,$data)){
- OC_HOOK::emit( "OC_FILESYSTEM", "write", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "write", array( 'storage'=>$this, 'path' => $path));
$this->clearFolderSizeCache($path);
}
}
public function unlink($path){
if($return=unlink($this->datadir.$path)){
- OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $path));
$this->clearFolderSizeCache($path);
}
return $return;
}
public function rename($path1,$path2){
if($return=rename($this->datadir.$path1,$this->datadir.$path2)){
- OC_HOOK::emit( "OC_FILESYSTEM", "rename", array( 'oldpath' => $path1, 'newpath' => $path2));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "rename", array( 'storage'=>$this, 'oldpath' => $path1, 'newpath' => $path2));
}
return $return;
}
@@ -177,29 +180,36 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
$path2.=$source;
}
if($return=copy($this->datadir.$path1,$this->datadir.$path2)){
- OC_HOOK::emit( "OC_FILESYSTEM", "create", array( 'path' => $path2));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "create", array( 'storage'=>$this, 'path' => $path2));
$this->clearFolderSizeCache($path);
}
return $return;
}
public function fopen($path,$mode){
+ $exists=$this->file_exists($path);
if($return=fopen($this->datadir.$path,$mode)){
switch($mode){
case 'r':
- OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path));
break;
case 'r+':
case 'w+':
case 'x+':
case 'a+':
- OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
- OC_HOOK::emit( "OC_FILESYSTEM", "write", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "write", array( 'storage'=>$this, 'path' => $path));
+ if(!$exists($path)){
+ OC_HOOK::emit( 'OC_FILESTORAGE', 'create', array( 'storage'=>$this, 'path' => $path));
+ }
$this->clearFolderSizeCache($path);
break;
case 'w':
case 'x':
case 'a':
- OC_HOOK::emit( "OC_FILESYSTEM", "write", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "write", array( 'storage'=>$this, 'path' => $path));
+ if(!$exists($path)){
+ OC_HOOK::emit( 'OC_FILESTORAGE', 'create', array( 'storage'=>$this, 'path' => $path));
+ }
$this->clearFolderSizeCache($path);
break;
}
@@ -362,7 +372,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
$fileStats = stat($this->datadir.$path);
if(copy($this->datadir.$path,$filename)){
touch($filename, $fileStats['mtime'], $fileStats['atime']);
- OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path));
return $filename;
}else{
return false;
@@ -373,7 +383,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
$fileStats = stat($tmpFile);
if(rename($tmpFile,$this->datadir.$path)){
touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']);
- OC_HOOK::emit( "OC_FILESYSTEM", "create", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "create", array( 'storage'=>$this, 'path' => $path));
$this->clearFolderSizeCache($path);
return true;
}else{
@@ -385,7 +395,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
$fileStats = stat($tmpFile);
if(move_uploaded_file($tmpFile,$this->datadir.$path)){
touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']);
- OC_HOOK::emit( "OC_FILESYSTEM", "create", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "create", array( 'storage'=>$this, 'path' => $path));
$this->clearFolderSizeCache($path);
return true;
}else{
@@ -402,7 +412,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
if ($item == '.' || $item == '..') continue;
if(is_file($dir.'/'.$item)){
if(unlink($dir.'/'.$item)){
- OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $dir.'/'.$item));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $dir.'/'.$item));
$this->clearFolderSizeCache($path);
}
}elseif(is_dir($dir.'/'.$item)){
@@ -412,7 +422,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
}
if($return=rmdir($dir)){
- OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $dir));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $dir));
$this->clearFolderSizeCache($path);
}
return $return;
@@ -450,7 +460,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
public function hash($type,$path,$raw){
if($return=hash_file($type,$this->datadir.$path,$raw)){
- OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
+ OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path));
}
return $return;
}