|
|
@ -22,13 +22,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Privde a common interface to all different storage options |
|
|
|
* Privde a common interface to all different storage options |
|
|
|
* |
|
|
|
|
|
|
|
* Hooks provided: |
|
|
|
|
|
|
|
* 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{ |
|
|
|
class OC_FILESTORAGE{ |
|
|
|
public function __construct($parameters){} |
|
|
|
public function __construct($parameters){} |
|
|
@ -86,16 +79,12 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ |
|
|
|
} |
|
|
|
} |
|
|
|
public function rmdir($path){ |
|
|
|
public function rmdir($path){ |
|
|
|
if($return=rmdir($this->datadir.$path)){ |
|
|
|
if($return=rmdir($this->datadir.$path)){ |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
} |
|
|
|
} |
|
|
|
return $return; |
|
|
|
return $return; |
|
|
|
} |
|
|
|
} |
|
|
|
public function opendir($path){ |
|
|
|
public function opendir($path){ |
|
|
|
if($return=opendir($this->datadir.$path)){ |
|
|
|
return opendir($this->datadir.$path); |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
public function is_dir($path){ |
|
|
|
public function is_dir($path){ |
|
|
|
return (is_dir($this->datadir.$path) or substr($path,-1)=='/'); |
|
|
|
return (is_dir($this->datadir.$path) or substr($path,-1)=='/'); |
|
|
@ -130,10 +119,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ |
|
|
|
return file_exists($this->datadir.$path); |
|
|
|
return file_exists($this->datadir.$path); |
|
|
|
} |
|
|
|
} |
|
|
|
public function readfile($path){ |
|
|
|
public function readfile($path){ |
|
|
|
if($return=readfile($this->datadir.$path)){ |
|
|
|
return readfile($this->datadir.$path); |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
public function filectime($path){ |
|
|
|
public function filectime($path){ |
|
|
|
return filectime($this->datadir.$path); |
|
|
|
return filectime($this->datadir.$path); |
|
|
@ -145,30 +131,23 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ |
|
|
|
return fileatime($this->datadir.$path); |
|
|
|
return fileatime($this->datadir.$path); |
|
|
|
} |
|
|
|
} |
|
|
|
public function file_get_contents($path){ |
|
|
|
public function file_get_contents($path){ |
|
|
|
if($return=file_get_contents($this->datadir.$path)){ |
|
|
|
return file_get_contents($this->datadir.$path); |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
public function file_put_contents($path,$data){ |
|
|
|
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)){ |
|
|
|
if($return=file_put_contents($this->datadir.$path,$data)){ |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "write", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public function unlink($path){ |
|
|
|
public function unlink($path){ |
|
|
|
if($return=unlink($this->datadir.$path)){ |
|
|
|
if($return=unlink($this->datadir.$path)){ |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
} |
|
|
|
} |
|
|
|
return $return; |
|
|
|
return $return; |
|
|
|
} |
|
|
|
} |
|
|
|
public function rename($path1,$path2){ |
|
|
|
public function rename($path1,$path2){ |
|
|
|
if($return=rename($this->datadir.$path1,$this->datadir.$path2)){ |
|
|
|
if($return=rename($this->datadir.$path1,$this->datadir.$path2)){ |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "rename", array( 'storage'=>$this, 'oldpath' => $path1, 'newpath' => $path2)); |
|
|
|
$this->clearFolderSizeCache($path1); |
|
|
|
|
|
|
|
$this->clearFolderSizeCache($path2); |
|
|
|
} |
|
|
|
} |
|
|
|
return $return; |
|
|
|
return $return; |
|
|
|
} |
|
|
|
} |
|
|
@ -181,36 +160,24 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ |
|
|
|
$path2.=$source; |
|
|
|
$path2.=$source; |
|
|
|
} |
|
|
|
} |
|
|
|
if($return=copy($this->datadir.$path1,$this->datadir.$path2)){ |
|
|
|
if($return=copy($this->datadir.$path1,$this->datadir.$path2)){ |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "create", array( 'storage'=>$this, 'path' => $path2)); |
|
|
|
$this->clearFolderSizeCache($path2); |
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return $return; |
|
|
|
return $return; |
|
|
|
} |
|
|
|
} |
|
|
|
public function fopen($path,$mode){ |
|
|
|
public function fopen($path,$mode){ |
|
|
|
$exists=$this->file_exists($path); |
|
|
|
|
|
|
|
if($return=fopen($this->datadir.$path,$mode)){ |
|
|
|
if($return=fopen($this->datadir.$path,$mode)){ |
|
|
|
switch($mode){ |
|
|
|
switch($mode){ |
|
|
|
case 'r': |
|
|
|
case 'r': |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'r+': |
|
|
|
case 'r+': |
|
|
|
case 'w+': |
|
|
|
case 'w+': |
|
|
|
case 'x+': |
|
|
|
case 'x+': |
|
|
|
case 'a+': |
|
|
|
case 'a+': |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "write", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
if(!$exists){ |
|
|
|
|
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', 'create', array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'w': |
|
|
|
case 'w': |
|
|
|
case 'x': |
|
|
|
case 'x': |
|
|
|
case 'a': |
|
|
|
case 'a': |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "write", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
if(!$exists){ |
|
|
|
|
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', 'create', array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -373,7 +340,6 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ |
|
|
|
$fileStats = stat($this->datadir.$path); |
|
|
|
$fileStats = stat($this->datadir.$path); |
|
|
|
if(copy($this->datadir.$path,$filename)){ |
|
|
|
if(copy($this->datadir.$path,$filename)){ |
|
|
|
touch($filename, $fileStats['mtime'], $fileStats['atime']); |
|
|
|
touch($filename, $fileStats['mtime'], $fileStats['atime']); |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
return $filename; |
|
|
|
return $filename; |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -384,7 +350,6 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ |
|
|
|
$fileStats = stat($tmpFile); |
|
|
|
$fileStats = stat($tmpFile); |
|
|
|
if(rename($tmpFile,$this->datadir.$path)){ |
|
|
|
if(rename($tmpFile,$this->datadir.$path)){ |
|
|
|
touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); |
|
|
|
touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "create", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
@ -396,7 +361,6 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ |
|
|
|
$fileStats = stat($tmpFile); |
|
|
|
$fileStats = stat($tmpFile); |
|
|
|
if(move_uploaded_file($tmpFile,$this->datadir.$path)){ |
|
|
|
if(move_uploaded_file($tmpFile,$this->datadir.$path)){ |
|
|
|
touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); |
|
|
|
touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "create", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
@ -413,7 +377,6 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ |
|
|
|
if ($item == '.' || $item == '..') continue; |
|
|
|
if ($item == '.' || $item == '..') continue; |
|
|
|
if(is_file($dir.'/'.$item)){ |
|
|
|
if(is_file($dir.'/'.$item)){ |
|
|
|
if(unlink($dir.'/'.$item)){ |
|
|
|
if(unlink($dir.'/'.$item)){ |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $dir.'/'.$item)); |
|
|
|
|
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
} |
|
|
|
} |
|
|
|
}elseif(is_dir($dir.'/'.$item)){ |
|
|
|
}elseif(is_dir($dir.'/'.$item)){ |
|
|
@ -423,7 +386,6 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if($return=rmdir($dir)){ |
|
|
|
if($return=rmdir($dir)){ |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "delete", array( 'storage'=>$this, 'path' => $dir)); |
|
|
|
|
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
$this->clearFolderSizeCache($path); |
|
|
|
} |
|
|
|
} |
|
|
|
return $return; |
|
|
|
return $return; |
|
|
@ -460,10 +422,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function hash($type,$path,$raw){ |
|
|
|
public function hash($type,$path,$raw){ |
|
|
|
if($return=hash_file($type,$this->datadir.$path,$raw)){ |
|
|
|
return hash_file($type,$this->datadir.$path,$raw); |
|
|
|
OC_HOOK::emit( 'OC_FILESTORAGE', "read", array( 'storage'=>$this, 'path' => $path)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function free_space($path){ |
|
|
|
public function free_space($path){ |
|
|
|