summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-01-14 21:06:26 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-01-19 09:16:15 +0100
commit15ae6b47edf08a1fd60a0941c3786372afad5baa (patch)
tree114df784b78a1a87b352082271f4dd8baeb22844 /apps/files_trashbin
parent4fcfedb03cb60fe60617fd8d7609d5d1397789a5 (diff)
downloadnextcloud-server-15ae6b47edf08a1fd60a0941c3786372afad5baa.tar.gz
nextcloud-server-15ae6b47edf08a1fd60a0941c3786372afad5baa.zip
replace hook with storage wrapper
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r--apps/files_trashbin/lib/hooks.php15
-rw-r--r--apps/files_trashbin/lib/storage.php67
-rw-r--r--apps/files_trashbin/lib/trashbin.php22
3 files changed, 80 insertions, 24 deletions
diff --git a/apps/files_trashbin/lib/hooks.php b/apps/files_trashbin/lib/hooks.php
index b6f0fb7e547..c6c69aaa23f 100644
--- a/apps/files_trashbin/lib/hooks.php
+++ b/apps/files_trashbin/lib/hooks.php
@@ -29,21 +29,6 @@ namespace OCA\Files_Trashbin;
class Hooks {
/**
- * Copy files to trash bin
- * @param array $params
- *
- * This function is connected to the delete signal of OC_Filesystem
- * to copy the file to the trash bin
- */
- public static function remove_hook($params) {
-
- if ( \OCP\App::isEnabled('files_trashbin') ) {
- $path = $params['path'];
- Trashbin::move2trash($path);
- }
- }
-
- /**
* clean up user specific settings if user gets deleted
* @param array $params array with uid
*
diff --git a/apps/files_trashbin/lib/storage.php b/apps/files_trashbin/lib/storage.php
new file mode 100644
index 00000000000..aa5d48b5fbe
--- /dev/null
+++ b/apps/files_trashbin/lib/storage.php
@@ -0,0 +1,67 @@
+<?php
+
+/**
+ * ownCloud
+ *
+ * @copyright (C) 2015 ownCloud, Inc.
+ *
+ * @author Bjoern Schiessle <schiessle@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\Files_Trashbin;
+
+use OC\Files\Storage\Wrapper\Wrapper;
+
+class Storage extends Wrapper {
+
+ private $mountPoint;
+ // remember already deleted files to avoid infinite loops if the trash bin
+ // move files across storages
+ private $deletedFiles = array();
+
+ function __construct($parameters) {
+ $this->mountPoint = $parameters['mountPoint'];
+ parent::__construct($parameters);
+ }
+
+ public function unlink($path) {
+ $normalized = \OC\Files\Filesystem::normalizePath($this->mountPoint . '/' . $path);
+ $result = true;
+ if (!isset($this->deletedFiles[$normalized])) {
+ $this->deletedFiles[$normalized] = $normalized;
+ $parts = explode('/', $normalized);
+ if (count($parts) > 3 && $parts[2] === 'files') {
+ $filesPath = implode('/', array_slice($parts, 3));
+ $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath);
+ } else {
+ $result = $this->storage->unlink($path);
+ }
+ unset($this->deletedFiles[$normalized]);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Setup the storate wrapper callback
+ */
+ public static function setupStorage() {
+ \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) {
+ return new \OCA\Files_Trashbin\Storage(array('storage' => $storage, 'mountPoint' => $mountPoint));
+ });
+ }
+
+}
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php
index 26257bd3817..f5cebea6b78 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -144,9 +144,10 @@ class Trashbin {
$size = 0;
list($owner, $ownerPath) = self::getUidAndFilename($file_path);
+ $view = new \OC\Files\View('/' . $user);
// file has been deleted in between
- if (empty($ownerPath)) {
- return false;
+ if (!$view->file_exists('/files/' . $file_path)) {
+ return true;
}
self::setUpTrash($user);
@@ -165,7 +166,8 @@ class Trashbin {
\OC_FileProxy::$enabled = false;
$trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp;
try {
- $sizeOfAddedFiles = self::copy_recursive('/files/'.$file_path, $trashPath, $view);
+ $sizeOfAddedFiles = $view->filesize('/files/' . $file_path);
+ $view->rename('/files/' . $file_path, $trashPath);
} catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
$sizeOfAddedFiles = false;
if ($view->file_exists($trashPath)) {
@@ -203,6 +205,8 @@ class Trashbin {
$ownerTrashSize += $size;
$ownerTrashSize -= self::expire($ownerTrashSize, $owner);
}
+
+ return ($sizeOfAddedFiles === false) ? false : true;
}
/**
@@ -321,8 +325,8 @@ class Trashbin {
} else {
// if location no longer exists, restore file in the root directory
if ($location !== '/' &&
- (!$view->is_dir('files' . $location) ||
- !$view->isCreatable('files' . $location))
+ (!$view->is_dir('files/' . $location) ||
+ !$view->isCreatable('files/' . $location))
) {
$location = '';
}
@@ -918,12 +922,12 @@ class Trashbin {
* register hooks
*/
public static function registerHooks() {
- //Listen to delete file signal
- \OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA\Files_Trashbin\Hooks", "remove_hook");
+ // create storage wrapper on setup
+ \OCP\Util::connectHook('OC_Filesystem', 'setup', 'OCA\Files_Trashbin\Storage', 'setupStorage');
//Listen to delete user signal
- \OCP\Util::connectHook('OC_User', 'pre_deleteUser', "OCA\Files_Trashbin\Hooks", "deleteUser_hook");
+ \OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook');
//Listen to post write hook
- \OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA\Files_Trashbin\Hooks", "post_write_hook");
+ \OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook');
}
/**