delete and restore of versions and share-keys now works

fix restore of the same file name
This commit is contained in:
Florin Peter 2013-04-27 23:51:26 +02:00 committed by Florin Peter
parent 5e11948598
commit 7a3ecd0429
1 changed files with 37 additions and 20 deletions

View File

@ -104,16 +104,24 @@ class Trashbin {
private static function retainVersions($view, $file_path, $filename, $timestamp) { private static function retainVersions($view, $file_path, $filename, $timestamp) {
$size = 0; $size = 0;
if (\OCP\App::isEnabled('files_versions')) { if (\OCP\App::isEnabled('files_versions')) {
$user = \OCP\User::getUser();
// disable proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$user = \OCP\User::getUser();
if ($view->is_dir('files_versions/' . $file_path)) { if ($view->is_dir('files_versions/' . $file_path)) {
$size += self::calculateSize(new \OC\Files\View('/' . $user . '/files_versions/' . $file_path)); $size += self::calculateSize(new \OC\Files\View('/' . $user . '/files_versions/' . $file_path));
$view->rename('files_versions/' . $file_path, 'files_trashbin/versions' . $filename . '.d' . $timestamp); $view->rename('files_versions/' . $file_path, 'files_trashbin/versions/' . $filename . '.d' . $timestamp);
} else if ($versions = \OCA\Files_Versions\Storage::getVersions($user, $file_path)) { } else if ($versions = \OCA\Files_Versions\Storage::getVersions($user, $file_path)) {
foreach ($versions as $v) { foreach ($versions as $v) {
$size += $view->filesize('files_versions' . $v['path'] . '.v' . $v['version']); $size += $view->filesize('files_versions' . $v['path'] . '.v' . $v['version']);
$view->rename('files_versions' . $v['path'] . '.v' . $v['version'], 'files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp); $view->rename('files_versions' . $v['path'] . '.v' . $v['version'], 'files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp);
} }
} }
// enable proxy
\OC_FileProxy::$enabled = $proxyStatus;
} }
return $size; return $size;
@ -250,6 +258,7 @@ class Trashbin {
$mtime = $view->filemtime($source); $mtime = $view->filemtime($source);
// disable proxy to prevent recursive calls // disable proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
// restore file // restore file
@ -278,13 +287,13 @@ class Trashbin {
self::setTrashbinSize($user, $trashbinSize); self::setTrashbinSize($user, $trashbinSize);
// enable proxy // enable proxy
\OC_FileProxy::$enabled = true; \OC_FileProxy::$enabled = $proxyStatus;
return true; return true;
} }
// enable proxy // enable proxy
\OC_FileProxy::$enabled = true; \OC_FileProxy::$enabled = $proxyStatus;
return false; return false;
} }
@ -304,26 +313,34 @@ class Trashbin {
private static function restoreVersions($view, $file, $filename, $ext, $location, $timestamp) { private static function restoreVersions($view, $file, $filename, $ext, $location, $timestamp) {
$size = 0; $size = 0;
if (\OCP\App::isEnabled('files_versions')) { if (\OCP\App::isEnabled('files_versions')) {
$user = \OCP\User::getUser(); // disable proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$user = \OCP\User::getUser();
if ($timestamp) { if ($timestamp) {
$versionedFile = $filename; $versionedFile = $filename;
} else { } else {
$versionedFile = $file; $versionedFile = $file;
} }
if ($view->is_dir('/files_trashbin/files/'.$file)) {
if ($view->is_dir('/files_trashbin/versions/'.$file)) {
$size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . 'files_trashbin/versions/' . $file)); $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . 'files_trashbin/versions/' . $file));
$view->rename(\OC\Files\Filesystem::normalizePath('files_trashbin/versions/' . $file), \OC\Files\Filesystem::normalizePath('files_versions/' . $location . '/' . $filename . $ext)); $view->rename(\OC\Files\Filesystem::normalizePath('files_trashbin/versions/' . $file), \OC\Files\Filesystem::normalizePath('files_versions/' . $location . '/' . $filename . $ext));
} else if ($versions = self::getVersionsFromTrash($versionedFile, $timestamp)) { } else if ($versions = self::getVersionsFromTrash($versionedFile, $timestamp)) {
foreach ($versions as $v) { foreach ($versions as $v) {
if ($timestamp) { if ($timestamp) {
$size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp); $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp);
$view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v); $view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v);
} else { } else {
$size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v); $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v);
$view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v); $view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v);
} }
} }
} }
// enable proxy
\OC_FileProxy::$enabled = $proxyStatus;
} }
return $size; return $size;
} }
@ -376,18 +393,18 @@ class Trashbin {
// handle keyfiles // handle keyfiles
$size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile)); $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile));
$view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename); $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext);
// handle share-keys // handle share-keys
if ($timestamp) { if ($timestamp) {
$sharekey .= '.d' . $timestamp; $sharekey .= '.d' . $timestamp;
} }
$view->rename($sharekey, 'files_encryption/share-keys/' . $location . '/' . $filename); $view->rename($sharekey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext);
} else { } else {
// handle keyfiles // handle keyfiles
$size += $view->filesize($keyfile); $size += $view->filesize($keyfile);
$view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . '.key'); $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext . '.key');
// handle share-keys // handle share-keys
$ownerShareKey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $source_location . '/' . $filename . '.' . $user. '.shareKey'); $ownerShareKey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $source_location . '/' . $filename . '.' . $user. '.shareKey');
@ -398,7 +415,7 @@ class Trashbin {
$size += $view->filesize($ownerShareKey); $size += $view->filesize($ownerShareKey);
// move only owners key // move only owners key
$view->rename($ownerShareKey, 'files_encryption/share-keys/' . $location . '/' . $filename . '.' . $user. '.shareKey'); $view->rename($ownerShareKey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext . '.' . $user. '.shareKey');
// try to re-share if file is shared // try to re-share if file is shared
$filesystemView = new \OC_FilesystemView('/'); $filesystemView = new \OC_FilesystemView('/');