diff options
author | Sam Tuke <samtuke@owncloud.com> | 2012-05-16 18:30:26 +0100 |
---|---|---|
committer | Sam Tuke <samtuke@owncloud.com> | 2012-05-16 18:30:26 +0100 |
commit | 9acd1065b0b96f5e82444e98273cc613872a8e28 (patch) | |
tree | 460f3d58f2690b832b627378625bb204f07253c6 | |
parent | fefa4412c4e4bab82517cca6f92680bcf0c71c2d (diff) | |
download | nextcloud-server-9acd1065b0b96f5e82444e98273cc613872a8e28.tar.gz nextcloud-server-9acd1065b0b96f5e82444e98273cc613872a8e28.zip |
made initial testing version of expireAll for version control \ngave some old vars new camelcase names
-rwxr-xr-x | apps/files_versions/ajax/getVersions.php | 2 | ||||
-rwxr-xr-x | apps/files_versions/history.php | 2 | ||||
-rw-r--r-- | apps/files_versions/js/versions.js | 4 | ||||
-rwxr-xr-x | apps/files_versions/versions.php | 118 | ||||
-rw-r--r-- | lib/filesystem.php | 4 |
5 files changed, 98 insertions, 32 deletions
diff --git a/apps/files_versions/ajax/getVersions.php b/apps/files_versions/ajax/getVersions.php index 8ef17d5a25c..5debb685891 100755 --- a/apps/files_versions/ajax/getVersions.php +++ b/apps/files_versions/ajax/getVersions.php @@ -13,7 +13,7 @@ $source = strip_tags( $source ); if( OCA_Versions\Storage::isversioned( $source ) ) { $count=5; //show the newest revisions - $versions = OCA_Versions\Storage::getversions( $source, $count); + $versions = OCA_Versions\Storage::getVersions( $source, $count); $versionsFormatted = array(); foreach ( $versions AS $version ) { diff --git a/apps/files_versions/history.php b/apps/files_versions/history.php index 7c03ef0e5e1..ea272e3735b 100755 --- a/apps/files_versions/history.php +++ b/apps/files_versions/history.php @@ -55,7 +55,7 @@ if ( isset( $_GET['path'] ) ) { if( OCA_Versions\Storage::isversioned( $path ) ) { $count = 999; //show the newest revisions - $versions = OCA_Versions\Storage::getversions( $path, $count); + $versions = OCA_Versions\Storage::getVersions( $path, $count); $tmpl->assign( 'versions', array_reverse( $versions ) ); diff --git a/apps/files_versions/js/versions.js b/apps/files_versions/js/versions.js index 2c92dfa3c65..eadf7a51039 100644 --- a/apps/files_versions/js/versions.js +++ b/apps/files_versions/js/versions.js @@ -25,8 +25,8 @@ $(document).ready(function(){ function createVersionsDropdown(filename, files) { - var historyUrl = '../apps/files_versions/history.php?path='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); - + var historyUrl = OC.linkTo('files_versions', 'history.php?path='+encodeURIComponent( $( '#dir' ).val() ).replace( /%2F/g, '/' )+'/'+encodeURIComponent( filename ) ) + var html = '<div id="dropdown" class="drop" data-file="'+files+'">'; html += '<div id="private">'; html += '<select data-placeholder="File Version" id="found_versions" class="chzen-select">'; diff --git a/apps/files_versions/versions.php b/apps/files_versions/versions.php index 89f7278deac..b9010182c09 100755 --- a/apps/files_versions/versions.php +++ b/apps/files_versions/versions.php @@ -27,7 +27,6 @@ class Storage { // // todo: // - port to oc_filesystem to enable network transparency - // - check if it works well together with encryption // - implement expire all function. And find a place to call it ;-) // - add transparent compression. first test if it´s worth it. @@ -69,7 +68,7 @@ class Storage { */ public static function store($filename) { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { - $versionsfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); + $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); $filesfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/files'; Storage::init(); @@ -95,7 +94,7 @@ class Storage { // check mininterval - $matches=glob($versionsfoldername.$filename.'.v*'); + $matches=glob($versionsFolderName.$filename.'.v*'); sort($matches); $parts=explode('.v',end($matches)); if((end($parts)+Storage::DEFAULTMININTERVAL)>time()){ @@ -105,13 +104,13 @@ class Storage { // create all parent folders $info=pathinfo($filename); - @mkdir($versionsfoldername.$info['dirname'],0700,true); + @mkdir($versionsFolderName.$info['dirname'], 0700, true); // store a new version of a file - copy($filesfoldername.$filename,$versionsfoldername.$filename.'.v'.time()); + copy($filesfoldername.$filename,$versionsFolderName.$filename.'.v'.time()); - // expire old revisions + // expire old revisions if necessary Storage::expire($filename); } } @@ -124,12 +123,12 @@ class Storage { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { - $versionsfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); + $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); $filesfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/files'; // rollback - if ( @copy($versionsfoldername.$filename.'.v'.$revision,$filesfoldername.$filename) ) { + if ( @copy($versionsFolderName.$filename.'.v'.$revision,$filesfoldername.$filename) ) { return true; @@ -148,10 +147,10 @@ class Storage { */ public static function isversioned($filename) { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { - $versionsfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); + $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); // check for old versions - $matches=glob($versionsfoldername.$filename.'.v*'); + $matches=glob($versionsFolderName.$filename.'.v*'); if(count($matches)>1){ return true; }else{ @@ -170,15 +169,15 @@ class Storage { * @param $count number of versions to return * @returns array */ - public static function getversions( $filename, $count = 0 ) { + public static function getVersions( $filename, $count = 0 ) { if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) { - $versionsfoldername = \OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); + $versionsFolderName = \OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); $versions = array(); // fetch for old versions - $matches = glob( $versionsfoldername.$filename.'.v*' ); + $matches = glob( $versionsFolderName.$filename.'.v*' ); sort( $matches ); @@ -188,12 +187,12 @@ class Storage { $i++; $versions[$i]['cur'] = 0; - $parts = explode( '.v',$ma ); + $parts = explode( '.v', $ma ); $versions[$i]['version'] = ( end( $parts ) ); // if file with modified date exists, flag it in array as currently enabled version $curFile['fileName'] = basename( $parts[0] ); - $curFile['filePath'] = \OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/files/'.$curFile['fileName']; + $curFile['filePath'] = \OCP\Config::getSystemValue('datadirectory').\OC_Filesystem::getRoot().'/'.$curFile['fileName']; ( \md5_file( $ma ) == \md5_file( $curFile['filePath'] ) ? $versions[$i]['fileMatch'] = 1 : $versions[$i]['fileMatch'] = 0 ); @@ -231,7 +230,8 @@ class Storage { return( array() ); } - } + + } @@ -241,28 +241,92 @@ class Storage { public static function expire($filename) { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { - $versionsfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); + $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); // check for old versions - $matches=glob($versionsfoldername.$filename.'.v*'); - if(count($matches)>\OCP\Config::getSystemValue('files_versionmaxversions', Storage::DEFAULTMAXVERSIONS)){ - $numbertodelete=count($matches-\OCP\Config::getSystemValue('files_versionmaxversions', Storage::DEFAULTMAXVERSIONS)); + $matches = glob( $versionsFolderName.$filename.'.v*' ); + + if( count( $matches ) > \OCP\Config::getSystemValue( 'files_versionmaxversions', Storage::DEFAULTMAXVERSIONS ) ) { + + $numberToDelete = count( $matches-\OCP\Config::getSystemValue( 'files_versionmaxversions', Storage::DEFAULTMAXVERSIONS ) ); // delete old versions of a file - $deleteitems=array_slice($matches,0,$numbertodelete); - foreach($deleteitems as $de){ - unlink($versionsfoldername.$filename.'.v'.$de); + $deleteItems = array_slice( $matches, 0, $numberToDelete ); + + foreach( $deleteItems as $de ) { + + unlink( $versionsFolderName.$filename.'.v'.$de ); + } } } } /** - * expire all old versions. + * @brief erase all old versions of all user files + * @return */ - public static function expireall($filename) { - // todo this should go through all the versions directories and delete all the not needed files and not needed directories. - // useful to be included in a cleanup cronjob. + public static function expireAll() { + + function deleteAll($directory, $empty = false) { + + if(substr($directory,-1) == "/") { + $directory = substr($directory,0,-1); + } + + if(!file_exists($directory) || !is_dir($directory)) { + + return false; + + } elseif(!is_readable($directory)) { + + return false; + + } else { + + $directoryHandle = opendir($directory); + + while ($contents = readdir($directoryHandle)) { + + if( $contents != '.' && $contents != '..') { + + $path = $directory . "/" . $contents; + + if( is_dir($path) ) { + + deleteAll($path); + + } else { + + unlink($path); + + } + } + + } + + closedir( $directoryHandle ); + + if( $empty == false ) { + + if(!rmdir($directory)) { + + return false; + + } + + } + + return true; + } + + } + + // FIXME: make this path dynamic + $dir = '/home/samtuke/owncloud/git/oc5/data/admin/versions'; + + ( deleteAll( $dir, 1 ) ? return true : return false ); + } diff --git a/lib/filesystem.php b/lib/filesystem.php index cac7e8648ef..4239971d9ee 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -290,8 +290,10 @@ class OC_Filesystem{ } /** - * get the fake root + * @brief get the relative path of the root data directory for the current user * @return string + * + * Returns path like /admin/files */ static public function getRoot(){ return self::$defaultInstance->getRoot(); |