summaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
authorSam Tuke <samtuke@owncloud.com>2012-06-19 19:42:40 +0100
committerSam Tuke <samtuke@owncloud.com>2012-06-19 19:42:40 +0100
commit28a72e0e3c25ecf8cc5ab61a4398ab687072b203 (patch)
treec1d3a0f381e1fb6202f282f09d15ffb698d33d17 /apps/files_versions
parentf11e4d7cd6c5cae9a0be52dff0bb2f32e20e7099 (diff)
downloadnextcloud-server-28a72e0e3c25ecf8cc5ab61a4398ab687072b203.tar.gz
nextcloud-server-28a72e0e3c25ecf8cc5ab61a4398ab687072b203.zip
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)
Diffstat (limited to 'apps/files_versions')
-rw-r--r--apps/files_versions/versions.php66
1 files changed, 44 insertions, 22 deletions
diff --git a/apps/files_versions/versions.php b/apps/files_versions/versions.php
index 44ce7c635aa..6feb0cbb9c7 100644
--- a/apps/files_versions/versions.php
+++ b/apps/files_versions/versions.php
@@ -303,66 +303,88 @@ class Storage {
*/
public static function expireAll() {
- function deleteAll($directory, $empty = false) {
+ function deleteAll( $directory, $empty = false ) {
- if(substr($directory,-1) == "/") {
- $directory = substr($directory,0,-1);
+ // strip leading slash
+ if( substr( $directory, 0, 1 ) == "/" ) {
+
+ $directory = substr( $directory, 1 );
+
+ }
+
+ // strip trailing slash
+ if( substr( $directory, -1) == "/" ) {
+
+ $directory = substr( $directory, 0, -1 );
+
}
- if(!file_exists($directory) || !is_dir($directory)) {
+ $view = new \OC_FilesystemView('');
+
+ if ( !$view->file_exists( $directory ) || !$view->is_dir( $directory ) ) {
return false;
- } elseif(!is_readable($directory)) {
+ } elseif( !$view->is_readable( $directory ) ) {
return false;
} 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
+
+ $directoryHandle = opendir( $foldername );
- while ($contents = readdir($directoryHandle)) {
+ while ( $contents = $view->readdir( $directoryHandle ) ) {
- if( $contents != '.' && $contents != '..') {
+ if ( $contents != '.' && $contents != '..') {
$path = $directory . "/" . $contents;
- if( is_dir($path) ) {
+ if ( $view->is_dir( $path ) ) {
- deleteAll($path);
+ deleteAll( $path );
} 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 true;
}
}
+
+ $dir = \OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
+
+ deleteAll( $dir, true );
+
+// if ( deleteAll( $dir, 1 ) ) {
+//
+// echo "<h1>deleted ok</h1>";
+//
+// } else {
+//
+// echo "<h1>not deleted</h1>";
+//
+// }
- /*
- // FIXME: make this path dynamic
- $dir = '/home/samtuke/owncloud/git/oc5/data/admin/versions';
-
- ( deleteAll( $dir, 1 ) ? return true : return false );
- */
}