restore fixed

This commit is contained in:
Florin Peter 2013-04-22 03:37:55 +02:00 committed by Florin Peter
parent 228c501515
commit 26e5ef193d
1 changed files with 40 additions and 22 deletions

View File

@ -141,6 +141,7 @@ class Trashbin {
//retain key files //retain key files
$keyfile = \OC\Files\Filesystem::normalizePath('files_encryption/keyfiles/' . $file_path); $keyfile = \OC\Files\Filesystem::normalizePath('files_encryption/keyfiles/' . $file_path);
if ($view->is_dir($keyfile) || $view->file_exists($keyfile . '.key')) { if ($view->is_dir($keyfile) || $view->file_exists($keyfile . '.key')) {
$user = \OCP\User::getUser(); $user = \OCP\User::getUser();
@ -176,6 +177,7 @@ class Trashbin {
* @return bool * @return bool
*/ */
public static function restore($file, $filename, $timestamp) { public static function restore($file, $filename, $timestamp) {
$user = \OCP\User::getUser(); $user = \OCP\User::getUser();
$view = new \OC\Files\View('/'.$user); $view = new \OC\Files\View('/'.$user);
@ -221,9 +223,6 @@ class Trashbin {
// restore file // restore file
$restoreResult = $view->rename($source, $target.$ext); $restoreResult = $view->rename($source, $target.$ext);
// enable proxy
\OC_FileProxy::$enabled = true;
// handle the restore result // handle the restore result
if( $restoreResult ) { if( $restoreResult ) {
$view->touch($target.$ext, $mtime); $view->touch($target.$ext, $mtime);
@ -246,9 +245,15 @@ class Trashbin {
self::setTrashbinSize($user, $trashbinSize); self::setTrashbinSize($user, $trashbinSize);
// enable proxy
\OC_FileProxy::$enabled = true;
return true; return true;
} }
// enable proxy
\OC_FileProxy::$enabled = true;
return false; return false;
} }
@ -302,7 +307,7 @@ class Trashbin {
* @param $location location if file * @param $location location if file
* @param $timestamp deleteion time * @param $timestamp deleteion time
* *
* @return size of restored versions * @return size of restored encrypted file
*/ */
private static function restoreEncryptionKeys($view, $file, $filename, $ext, $location, $timestamp) { private static function restoreEncryptionKeys($view, $file, $filename, $ext, $location, $timestamp) {
// Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!) // Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!)
@ -310,18 +315,28 @@ class Trashbin {
if (\OCP\App::isEnabled('files_encryption')) { if (\OCP\App::isEnabled('files_encryption')) {
$user = \OCP\User::getUser(); $user = \OCP\User::getUser();
$parts = pathinfo($file); $path_parts = pathinfo($file);
if ($view->is_dir('/files_trashbin/files/'.$file)) { $source_location = $path_parts['dirname'];
$keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $parts['dirname'] . '/' . $filename);
if ($view->is_dir('/files_trashbin/keyfiles/'.$file)) {
if($source_location != '.') {
$keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename);
} else { } else {
$keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $parts['dirname'] . '/' . $filename . '.key'); $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename);
}
} else {
$keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename . '.key');
} }
if ($view->file_exists($keyfile)) {
if ($timestamp) { if ($timestamp) {
$keyfile .= '.d' . $timestamp; $keyfile .= '.d' . $timestamp;
} }
if ($view->is_dir('/files_trashbin/files/'.$file)) {
// disable proxy to prevent recursive calls
\OC_FileProxy::$enabled = false;
if ($view->file_exists($keyfile)) {
if ($view->is_dir($keyfile)) {
$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);
} else { } else {
@ -332,6 +347,9 @@ class Trashbin {
//TODO restore share-keys //TODO restore share-keys
//... //...
// enable proxy
\OC_FileProxy::$enabled = true;
} }
return $size; return $size;
} }