summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorFlorin Peter <fp@datawerk.de>2013-04-22 03:37:55 +0200
committerFlorin Peter <github@florin-peter.de>2013-04-28 20:48:30 +0200
commit26e5ef193d4285f2aee13c5b811d6d0df66e4792 (patch)
treeb89788ad176b5f34c87bcc982f2b2553c3f8e043 /apps
parent228c5015158687b3dc1691c84904b3f8d3f91d11 (diff)
downloadnextcloud-server-26e5ef193d4285f2aee13c5b811d6d0df66e4792.tar.gz
nextcloud-server-26e5ef193d4285f2aee13c5b811d6d0df66e4792.zip
restore fixed
Diffstat (limited to 'apps')
-rw-r--r--apps/files_trashbin/lib/trash.php62
1 files changed, 40 insertions, 22 deletions
diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php
index d3edaa01bc6..653242793be 100644
--- a/apps/files_trashbin/lib/trash.php
+++ b/apps/files_trashbin/lib/trash.php
@@ -64,7 +64,7 @@ class Trashbin {
}
$sizeOfAddedFiles = self::copy_recursive($file_path, 'files_trashbin/files/'.$filename.'.d'.$timestamp, $view);
-
+
if ( $view->file_exists('files_trashbin/files/'.$filename.'.d'.$timestamp) ) {
$trashbinSize += $sizeOfAddedFiles;
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`type`,`mime`,`user`) VALUES (?,?,?,?,?,?)");
@@ -141,6 +141,7 @@ class Trashbin {
//retain key files
$keyfile = \OC\Files\Filesystem::normalizePath('files_encryption/keyfiles/' . $file_path);
+
if ($view->is_dir($keyfile) || $view->file_exists($keyfile . '.key')) {
$user = \OCP\User::getUser();
@@ -176,7 +177,8 @@ class Trashbin {
* @return bool
*/
public static function restore($file, $filename, $timestamp) {
- $user = \OCP\User::getUser();
+
+ $user = \OCP\User::getUser();
$view = new \OC\Files\View('/'.$user);
$trashbinSize = self::getTrashbinSize($user);
@@ -221,9 +223,6 @@ class Trashbin {
// restore file
$restoreResult = $view->rename($source, $target.$ext);
- // enable proxy
- \OC_FileProxy::$enabled = true;
-
// handle the restore result
if( $restoreResult ) {
$view->touch($target.$ext, $mtime);
@@ -236,7 +235,7 @@ class Trashbin {
$trashbinSize -= $view->filesize($target.$ext);
}
- $trashbinSize -= self::restoreVersions($view, $file, $filename, $ext, $location, $timestamp);
+ $trashbinSize -= self::restoreVersions($view, $file, $filename, $ext, $location, $timestamp);
$trashbinSize -= self::restoreEncryptionKeys($view, $file, $filename, $ext, $location, $timestamp);
if ( $timestamp ) {
@@ -245,10 +244,16 @@ class Trashbin {
}
self::setTrashbinSize($user, $trashbinSize);
-
+
+ // enable proxy
+ \OC_FileProxy::$enabled = true;
+
return true;
}
+ // enable proxy
+ \OC_FileProxy::$enabled = true;
+
return false;
}
@@ -302,7 +307,7 @@ class Trashbin {
* @param $location location if file
* @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) {
// Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!)
@@ -310,28 +315,41 @@ class Trashbin {
if (\OCP\App::isEnabled('files_encryption')) {
$user = \OCP\User::getUser();
- $parts = pathinfo($file);
- if ($view->is_dir('/files_trashbin/files/'.$file)) {
- $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $parts['dirname'] . '/' . $filename);
+ $path_parts = pathinfo($file);
+ $source_location = $path_parts['dirname'];
+
+ if ($view->is_dir('/files_trashbin/keyfiles/'.$file)) {
+ if($source_location != '.') {
+ $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename);
+ } else {
+ $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename);
+ }
} else {
- $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $parts['dirname'] . '/' . $filename . '.key');
+ $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename . '.key');
}
- if ($view->file_exists($keyfile)) {
- if ($timestamp) {
- $keyfile .= '.d' . $timestamp;
- }
- if ($view->is_dir('/files_trashbin/files/'.$file)) {
- $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile));
- $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename);
+ if ($timestamp) {
+ $keyfile .= '.d' . $timestamp;
+ }
+
+ // 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));
+ $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename);
} else {
$size += $view->filesize($keyfile);
- $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . '.key');
+ $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . '.key');
}
}
- //TODO restore share-keys
- //...
+ //TODO restore share-keys
+ //...
+
+ // enable proxy
+ \OC_FileProxy::$enabled = true;
}
return $size;
}