]> source.dussan.org Git - nextcloud-server.git/commitdiff
delete files right away in case of a encryption exception 3841/head
authorBjoern Schiessle <bjoern@schiessle.org>
Tue, 14 Mar 2017 11:05:25 +0000 (12:05 +0100)
committerBjoern Schiessle <bjoern@schiessle.org>
Tue, 14 Mar 2017 11:11:28 +0000 (12:11 +0100)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
apps/files_trashbin/lib/Storage.php
apps/files_trashbin/tests/StorageTest.php

index b8f154ea051a267ef68219f305360b70c285a7ff..e3fe648281c7de2f1af18228b598a4f199e0be7a 100644 (file)
@@ -28,6 +28,8 @@ namespace OCA\Files_Trashbin;
 use OC\Files\Filesystem;
 use OC\Files\Storage\Wrapper\Wrapper;
 use OC\Files\View;
+use OCP\Encryption\Exceptions\GenericEncryptionException;
+use OCP\ILogger;
 use OCP\IUserManager;
 
 class Storage extends Wrapper {
@@ -55,15 +57,21 @@ class Storage extends Wrapper {
        /** @var  IUserManager */
        private $userManager;
 
+       /** @var ILogger */
+       private $logger;
+
        /**
         * Storage constructor.
         *
         * @param array $parameters
         * @param IUserManager|null $userManager
         */
-       public function __construct($parameters, IUserManager $userManager = null) {
+       public function __construct($parameters,
+                                                               IUserManager $userManager = null,
+                                                               ILogger $logger = null) {
                $this->mountPoint = $parameters['mountPoint'];
                $this->userManager = $userManager;
+               $this->logger = $logger;
                parent::__construct($parameters);
        }
 
@@ -147,11 +155,20 @@ class Storage extends Wrapper {
         * @return bool true if the operation succeeded, false otherwise
         */
        public function unlink($path) {
-               if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) {
-                       $result = $this->doDelete($path, 'unlink', true);
-                       unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]);
-               } else {
-                       $result = $this->doDelete($path, 'unlink');
+               try {
+                       if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) {
+                               $result = $this->doDelete($path, 'unlink', true);
+                               unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]);
+                       } else {
+                               $result = $this->doDelete($path, 'unlink');
+                       }
+               } catch (GenericEncryptionException $e) {
+                       // in case of a encryption exception we delete the file right away
+                       $this->logger->info(
+                               "Can't move file" .  $path .
+                               "to the trash bin, therefore it was deleted right away");
+
+                       $result = $this->storage->unlink($path);
                }
 
                return $result;
@@ -251,7 +268,8 @@ class Storage extends Wrapper {
                \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) {
                        return new \OCA\Files_Trashbin\Storage(
                                array('storage' => $storage, 'mountPoint' => $mountPoint),
-                               \OC::$server->getUserManager()
+                               \OC::$server->getUserManager(),
+                               \OC::$server->getLogger()
                        );
                }, 1);
        }
index 2aebe6414f7d5df80885fd4856b06a5f75af2b78..52d5f05614884187c0e67b48f721d2301fa7164f 100644 (file)
@@ -31,6 +31,7 @@ namespace OCA\Files_Trashbin\Tests;
 
 use OC\Files\Storage\Temporary;
 use OC\Files\Filesystem;
+use OCP\ILogger;
 
 /**
  * Class Storage
@@ -528,9 +529,11 @@ class StorageTest extends \Test\TestCase {
                        ->disableOriginalConstructor()->getMock();
                $userManager->expects($this->any())
                        ->method('userExists')->willReturn($userExists);
+               $logger = $this->getMockBuilder(ILogger::class)->getMock();
                $storage = new \OCA\Files_Trashbin\Storage(
                        ['mountPoint' => $mountPoint, 'storage' => $tmpStorage],
-                       $userManager
+                       $userManager,
+                       $logger
                );
 
                $this->assertSame($expected,