summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJakob Sack <kde@jakobsack.de>2011-04-18 12:03:06 +0200
committerJakob Sack <kde@jakobsack.de>2011-04-18 12:03:06 +0200
commit761a5178887032369252d7ffacad843cb3585b46 (patch)
tree08adfaa10ae98afe4364435f828a090fe92c3f75 /lib
parent329d804032db1691ea539e77b12fa7bb52387440 (diff)
parentb8e1788ed0c3da2cd70b9d2bc50c5273b8a65ff7 (diff)
downloadnextcloud-server-761a5178887032369252d7ffacad843cb3585b46.tar.gz
nextcloud-server-761a5178887032369252d7ffacad843cb3585b46.zip
Merge branch 'refactoring' of git://anongit.kde.org/owncloud into refactoring
Diffstat (limited to 'lib')
-rw-r--r--lib/fileobserver.php82
-rw-r--r--lib/filestorage.php63
2 files changed, 25 insertions, 120 deletions
diff --git a/lib/fileobserver.php b/lib/fileobserver.php
deleted file mode 100644
index ac9f2513c7b..00000000000
--- a/lib/fileobserver.php
+++ /dev/null
@@ -1,82 +0,0 @@
-<?php
-
-/**
-* ownCloud
-*
-* @author Frank Karlitschek
-* @copyright 2010 Frank Karlitschek karlitschek@kde.org
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-define('OC_FILEACTION_WRITE',2);
-define('OC_FILEACTION_READ',4);
-define('OC_FILEACTION_DELETE',8);
-define('OC_FILEACTION_CREATE',16);
-define('OC_FILEACTION_RENAME',32);
-
-/**
- * base class for file observers
- */
-class OC_FILEOBSERVER{
- private $mask;
-
- public function __construct($arguments){}
-
- public function __get($name){
- switch($name){
- case 'mask':
- return $this->mask;
- }
- }
-
- public function notify($path,$action,$storage){}
-}
-
-/**
- * observer that makes automatic backups
- */
-class OC_FILEOBSERVER_BACKUP extends OC_FILEOBSERVER{
- private $storage;
-
- public function __construct($arguments){
- $this->mask=OC_FILEACTION_WRITE+OC_FILEACTION_DELETE+OC_FILEACTION_CREATE+OC_FILEACTION_RENAME;
- $this->storage=$arguments['storage'];
- }
-
- public function notify($path,$action,$storage){
- switch($action){
- case OC_FILEACTION_DELETE:
- if($storage->is_dir($path)){
- $this->storage->delTree($path);
- }else{
- $this->storage->unlink($path);
- }
- break;
- case OC_FILEACTION_CREATE:
- if($storage->is_dir($path)){
- $this->storage->mkdir($path);
- break;
- }
- case OC_FILEACTION_WRITE:
- $tmpFile=$storage->toTmpFile($path);
- $this->storage->fromTmpFile($tmpFile,$path);
- break;
- case OC_FILEACTION_RENAME:
- list($source,$target)=explode('->',$path);
- $this->storage->rename($source,$target);
- }
- }
-}
-?> \ No newline at end of file
diff --git a/lib/filestorage.php b/lib/filestorage.php
index e6305a51bac..c20d6d7b3e0 100644
--- a/lib/filestorage.php
+++ b/lib/filestorage.php
@@ -22,29 +22,15 @@
/**
* Privde a common interface to all different storage options
+ *
+ * Hooks provided:
+ * read(path)
+ * write(path)
+ * create(path)
+ * delete(path)
+ * rename(oldpath,newpath)
*/
class OC_FILESTORAGE{
- private $observers=array();
- /**
- * add an observer to the list
- * @param OC_FILEOBERSER observer
- */
- public function addObserver($observer){
- $this->observers[]=$observer;
- }
- /**
- * notify the observers about an action
- * @param int action a combination of OC_FILEACTION_WRITE and OC_FILEACTION_READ
- * @param string path relative path of the file
- */
- public function notifyObservers($path,$action){
- foreach($this->observers as $observer){
- if($observer->mask & $action){
- $observer->notify($path,$action,$this);
- }
- }
- }
-
public function __construct($parameters){}
public function mkdir($path){}
public function rmdir($path){}
@@ -99,14 +85,14 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
public function rmdir($path){
if($return=rmdir($this->datadir.$path)){
- $this->notifyObservers($path,OC_FILEACTION_DELETE);
+ OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $path));
$this->clearFolderSizeCache($path);
}
return $return;
}
public function opendir($path){
if($return=opendir($this->datadir.$path)){
- $this->notifyObservers($path,OC_FILEACTION_READ);
+ OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
}
return $return;
}
@@ -144,7 +130,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
public function readfile($path){
if($return=readfile($this->datadir.$path)){
- $this->notifyObservers($path,OC_FILEACTION_READ);
+ OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
}
return $return;
}
@@ -159,26 +145,26 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
public function file_get_contents($path){
if($return=file_get_contents($this->datadir.$path)){
- $this->notifyObservers($path,OC_FILEACTION_READ);
+ OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
}
return $return;
}
public function file_put_contents($path,$data){
if($return=file_put_contents($this->datadir.$path,$data)){
- $this->notifyObservers($path,OC_FILEACTION_WRITE);
+ OC_HOOK::emit( "OC_FILESYSTEM", "write", array( 'path' => $path));
$this->clearFolderSizeCache($path);
}
}
public function unlink($path){
if($return=unlink($this->datadir.$path)){
- $this->notifyObservers($path,OC_FILEACTION_DELETE);
+ OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $path));
$this->clearFolderSizeCache($path);
}
return $return;
}
public function rename($path1,$path2){
if($return=rename($this->datadir.$path1,$this->datadir.$path2)){
- $this->notifyObservers($path1.'->'.$path2,OC_FILEACTION_RENAME);
+ OC_HOOK::emit( "OC_FILESYSTEM", "rename", array( 'oldpath' => $path1, 'newpath' => $path2));
}
return $return;
}
@@ -191,7 +177,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
$path2.=$source;
}
if($return=copy($this->datadir.$path1,$this->datadir.$path2)){
- $this->notifyObservers($path2,OC_FILEACTION_CREATE);
+ OC_HOOK::emit( "OC_FILESYSTEM", "create", array( 'path' => $path2));
$this->clearFolderSizeCache($path);
}
return $return;
@@ -200,19 +186,20 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
if($return=fopen($this->datadir.$path,$mode)){
switch($mode){
case 'r':
- $this->notifyObservers($path,OC_FILEACTION_READ);
+ OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
break;
case 'r+':
case 'w+':
case 'x+':
case 'a+':
- $this->notifyObservers($path,OC_FILEACTION_READ | OC_FILEACTION_WRITE);
+ OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
+ OC_HOOK::emit( "OC_FILESYSTEM", "write", array( 'path' => $path));
$this->clearFolderSizeCache($path);
break;
case 'w':
case 'x':
case 'a':
- $this->notifyObservers($path,OC_FILEACTION_WRITE);
+ OC_HOOK::emit( "OC_FILESYSTEM", "write", array( 'path' => $path));
$this->clearFolderSizeCache($path);
break;
}
@@ -375,7 +362,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']);
- $this->notifyObservers($path,OC_FILEACTION_READ);
+ OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
return $filename;
}else{
return false;
@@ -386,7 +373,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']);
- $this->notifyObservers($path,OC_FILEACTION_CREATE);
+ OC_HOOK::emit( "OC_FILESYSTEM", "create", array( 'path' => $path));
$this->clearFolderSizeCache($path);
return true;
}else{
@@ -398,7 +385,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']);
- $this->notifyObservers($path,OC_FILEACTION_CREATE);
+ OC_HOOK::emit( "OC_FILESYSTEM", "create", array( 'path' => $path));
$this->clearFolderSizeCache($path);
return true;
}else{
@@ -415,7 +402,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
if ($item == '.' || $item == '..') continue;
if(is_file($dir.'/'.$item)){
if(unlink($dir.'/'.$item)){
- $this->notifyObservers($dir.'/'.$item,OC_FILEACTION_DELETE);
+ OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $dir.'/'.$item));
$this->clearFolderSizeCache($path);
}
}elseif(is_dir($dir.'/'.$item)){
@@ -425,7 +412,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
}
if($return=rmdir($dir)){
- $this->notifyObservers($dir,OC_FILEACTION_DELETE);
+ OC_HOOK::emit( "OC_FILESYSTEM", "delete", array( 'path' => $dir));
$this->clearFolderSizeCache($path);
}
return $return;
@@ -463,7 +450,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
public function hash($type,$path,$raw){
if($return=hash_file($type,$this->datadir.$path,$raw)){
- $this->notifyObservers($path,OC_FILEACTION_READ);
+ OC_HOOK::emit( "OC_FILESYSTEM", "read", array( 'path' => $path));
}
return $return;
}