* of the stored versions along the actual file
*/
public static function rename_hook($params) {
- $versions_fileview = \OCP\Files::getStorage('files_versions');
- $rel_oldpath = $params['oldpath'];
- $abs_oldpath = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$rel_oldpath.'.v';
- $abs_newpath = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$params['newpath'].'.v';
- if(Storage::isversioned($rel_oldpath)) {
- $info=pathinfo($abs_newpath);
- if(!file_exists($info['dirname'])) mkdir($info['dirname'], 0750, true);
- $versions = Storage::getVersions($rel_oldpath);
- foreach ($versions as $v) {
- rename($abs_oldpath.$v['version'], $abs_newpath.$v['version']);
- }
+ if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {\r
+ \r
+ $versions = new Storage( new \OC_FilesystemView('') );\r
+ \r
+ $oldpath = $params['oldpath'];
+ $newpath = $params['newpath'];\r
+ \r
+ if($oldpath<>'' && $newpath<>'') $versions->rename( $oldpath, $newpath );\r
+ \r
}
}
-
+
}
const DEFAULTENABLED=true;
const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota
- private static $max_versions_per_interval = array(1 => array('intervalEndsAfter' => 10, //first 10sec, one version every 2sec
+ private static $max_versions_per_interval = array(
+ 1 => array('intervalEndsAfter' => 10, //first 10sec, one version every 2sec
'step' => 2),
2 => array('intervalEndsAfter' => 60, //next minute, one version every 10sec\r
'step' => 10),
$versions_fileview = new \OC_FilesystemView('/'.$uid .'/files_versions');
\r
$abs_path = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$filename.'.v';\r
- if(Storage::isversioned($filename)) {\r
- $versions = self::getVersions($filename);\r
+ if( ($versions = self::getVersions($filename)) ) {\r
if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) {\r
$versionsSize = self::calculateSize($uid);\r
}\r
}
}
+ /**\r
+ * Delete versions of a file\r
+ */\r
+ public static function rename($oldpath, $newpath) {
+ error_log("oldpath: $oldpath");
+ error_log("newpath: $newpath");\r
+ list($uid, $oldpath) = self::getUidAndFilename($oldpath);
+ list($uidn, $newpath) = self::getUidAndFilename($newpath);\r
+ $versions_view = new \OC_FilesystemView('/'.$uid .'/files_versions');
+ $files_view = new \OC_FilesystemView('/'.$uid .'/files');\r
+ \r
+ if ( $files_view->is_dir($oldpath) && $versions_view->is_dir($oldpath) ) {
+ $versions_view->rename($oldpath, $newpath);
+ } else if ( ($versions = Storage::getVersions($oldpath)) ) {\r
+ $info=pathinfo($abs_newpath);\r
+ if(!file_exists($info['dirname'])) mkdir($info['dirname'], 0750, true);\r
+ $versions = Storage::getVersions($oldpath);\r
+ foreach ($versions as $v) {
+ error_log("rename(".$oldpath.'.v'.$v['version'].", ". $newpath.'.v'.$v['version'].")");
+ $versions_view->rename($oldpath.'.v'.$v['version'], $newpath.'.v'.$v['version']);\r
+ }\r
+ }\r
+ }
+
/**
* rollback to an old version of a file.
*/
$users_view = new \OC_FilesystemView('/'.$uid);
//first create a new version
- if ( !$users_view->file_exists('files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename))) {
- $version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename);
+ $version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename);
+ if ( !$users_view->file_exists($version)) {
$users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename));
+ $versionCreated = true;
}
// rollback
Storage::expire($filename);
return true;
- }else{
- if (isset($version) ) {
- $users_view->unlink($version);
- return false;
- }
+ }else if ( $versionCreated ) {
+ $users_view->unlink($version);
}
}
+ return false;
}
- /**
- * check if old versions of a file exist.
- */
- public static function isversioned($filename) {
- if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
- list($uid, $filename) = self::getUidAndFilename($filename);
- $versions_fileview = new \OC_FilesystemView('/'.$uid.'/files_versions');
-
- $versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);
-
- // check for old versions
- $matches=glob($versionsName.'.v*');
- if(count($matches)>0) {
- return true;
- }else{
- return false;
- }
- }else{
- return(false);
- }
- }
-
-
/**
* @brief get a list of all available versions of a file in descending chronological order
for ($i=1; $i<$numOfVersions; $i++) {
if ( $nextInterval == -1 || $versions[$i]['version'] >= $nextInterval ) {
if ( $versions[$i]['version'] > $nextVersion ) {
- //distance between two version to small, delete version
+ //distance between two version too small, delete version
$versions_fileview->unlink($versions[$i]['path'].'.v'.$versions[$i]['version']);
$availableSpace += $versions[$i]['size'];
$versionsSize -= $versions[$i]['size'];