Fixed deleteAll function for deleting all old versions of files (expireAll)
Added new readdir() method to all storage classes and handlers (only working implementation in local.php)
This commit is contained in:
parent
f11e4d7cd6
commit
28a72e0e3c
|
@ -49,6 +49,7 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{
|
||||||
OC_FakeDirStream::$dirs[$id]=$content;
|
OC_FakeDirStream::$dirs[$id]=$content;
|
||||||
return opendir('fakedir://'.$id);
|
return opendir('fakedir://'.$id);
|
||||||
}
|
}
|
||||||
|
public function readdir($path){}
|
||||||
public function stat($path){
|
public function stat($path){
|
||||||
$ctime=filectime($this->path);
|
$ctime=filectime($this->path);
|
||||||
$path=$this->stripPath($path);
|
$path=$this->stripPath($path);
|
||||||
|
|
|
@ -139,6 +139,8 @@ class OC_Filestorage_Shared extends OC_Filestorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function readdir( $path ) {}
|
||||||
|
|
||||||
public function is_dir($path) {
|
public function is_dir($path) {
|
||||||
if ($path == "" || $path == "/") {
|
if ($path == "" || $path == "/") {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -303,48 +303,62 @@ class Storage {
|
||||||
*/
|
*/
|
||||||
public static function expireAll() {
|
public static function expireAll() {
|
||||||
|
|
||||||
function deleteAll($directory, $empty = false) {
|
function deleteAll( $directory, $empty = false ) {
|
||||||
|
|
||||||
|
// strip leading slash
|
||||||
|
if( substr( $directory, 0, 1 ) == "/" ) {
|
||||||
|
|
||||||
|
$directory = substr( $directory, 1 );
|
||||||
|
|
||||||
if(substr($directory,-1) == "/") {
|
|
||||||
$directory = substr($directory,0,-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!file_exists($directory) || !is_dir($directory)) {
|
// strip trailing slash
|
||||||
|
if( substr( $directory, -1) == "/" ) {
|
||||||
|
|
||||||
|
$directory = substr( $directory, 0, -1 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$view = new \OC_FilesystemView('');
|
||||||
|
|
||||||
|
if ( !$view->file_exists( $directory ) || !$view->is_dir( $directory ) ) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} elseif(!is_readable($directory)) {
|
} elseif( !$view->is_readable( $directory ) ) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$directoryHandle = opendir($directory);
|
$foldername = \OCP\Config::getSystemValue('datadirectory') .'/' . \OCP\USER::getUser() .'/' . $directory; // have to set an absolute path for use with PHP's opendir as OC version doesn't work
|
||||||
|
|
||||||
while ($contents = readdir($directoryHandle)) {
|
$directoryHandle = opendir( $foldername );
|
||||||
|
|
||||||
if( $contents != '.' && $contents != '..') {
|
while ( $contents = $view->readdir( $directoryHandle ) ) {
|
||||||
|
|
||||||
|
if ( $contents != '.' && $contents != '..') {
|
||||||
|
|
||||||
$path = $directory . "/" . $contents;
|
$path = $directory . "/" . $contents;
|
||||||
|
|
||||||
if( is_dir($path) ) {
|
if ( $view->is_dir( $path ) ) {
|
||||||
|
|
||||||
deleteAll($path);
|
deleteAll( $path );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
unlink($path);
|
$view->unlink( \OCP\USER::getUser() .'/' . $path ); // TODO: make unlink use same system path as is_dir
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir( $directoryHandle );
|
//$view->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV
|
||||||
|
|
||||||
if( $empty == false ) {
|
if ( $empty == false ) {
|
||||||
|
|
||||||
if(!rmdir($directory)) {
|
if ( !$view->rmdir( $directory ) ) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -357,12 +371,20 @@ class Storage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
$dir = \OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
|
||||||
// FIXME: make this path dynamic
|
|
||||||
$dir = '/home/samtuke/owncloud/git/oc5/data/admin/versions';
|
deleteAll( $dir, true );
|
||||||
|
|
||||||
|
// if ( deleteAll( $dir, 1 ) ) {
|
||||||
|
//
|
||||||
|
// echo "<h1>deleted ok</h1>";
|
||||||
|
//
|
||||||
|
// } else {
|
||||||
|
//
|
||||||
|
// echo "<h1>not deleted</h1>";
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
( deleteAll( $dir, 1 ) ? return true : return false );
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ abstract class OC_Filestorage{
|
||||||
abstract public function mkdir($path);
|
abstract public function mkdir($path);
|
||||||
abstract public function rmdir($path);
|
abstract public function rmdir($path);
|
||||||
abstract public function opendir($path);
|
abstract public function opendir($path);
|
||||||
|
abstract public function readdir($path);
|
||||||
abstract public function is_dir($path);
|
abstract public function is_dir($path);
|
||||||
abstract public function is_file($path);
|
abstract public function is_file($path);
|
||||||
abstract public function stat($path);
|
abstract public function stat($path);
|
||||||
|
|
|
@ -20,6 +20,9 @@ class OC_Filestorage_Local extends OC_Filestorage{
|
||||||
public function opendir($path){
|
public function opendir($path){
|
||||||
return opendir($this->datadir.$path);
|
return opendir($this->datadir.$path);
|
||||||
}
|
}
|
||||||
|
public function readdir($handle){
|
||||||
|
return readdir($handle);
|
||||||
|
}
|
||||||
public function is_dir($path){
|
public function is_dir($path){
|
||||||
if(substr($path,-1)=='/'){
|
if(substr($path,-1)=='/'){
|
||||||
$path=substr($path,0,-1);
|
$path=substr($path,0,-1);
|
||||||
|
|
|
@ -399,6 +399,9 @@ class OC_Filesystem{
|
||||||
static public function opendir($path){
|
static public function opendir($path){
|
||||||
return self::$defaultInstance->opendir($path);
|
return self::$defaultInstance->opendir($path);
|
||||||
}
|
}
|
||||||
|
static public function readdir($path){
|
||||||
|
return self::$defaultInstance->readdir($path);
|
||||||
|
}
|
||||||
static public function is_dir($path){
|
static public function is_dir($path){
|
||||||
return self::$defaultInstance->is_dir($path);
|
return self::$defaultInstance->is_dir($path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,10 @@ class OC_FilesystemView {
|
||||||
public function opendir($path){
|
public function opendir($path){
|
||||||
return $this->basicOperation('opendir',$path,array('read'));
|
return $this->basicOperation('opendir',$path,array('read'));
|
||||||
}
|
}
|
||||||
|
public function readdir($handle){
|
||||||
|
$fsLocal= new OC_Filestorage_Local( array( 'datadir' => '/' ) );
|
||||||
|
return $fsLocal->readdir( $handle );
|
||||||
|
}
|
||||||
public function is_dir($path){
|
public function is_dir($path){
|
||||||
if($path=='/'){
|
if($path=='/'){
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue