]> source.dussan.org Git - nextcloud-server.git/commitdiff
Remove SharedCache::getNumericStorageId to let CacheWrapper do it
authorVincent Petry <pvince81@owncloud.com>
Thu, 16 Feb 2017 10:47:16 +0000 (11:47 +0100)
committerMorris Jobke <hey@morrisjobke.de>
Thu, 23 Mar 2017 06:02:48 +0000 (00:02 -0600)
The CacheWrapper will properly forward the call to the wrapped cache.

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
apps/files_sharing/lib/Cache.php
apps/files_sharing/tests/CacheTest.php
build/integration/features/external-storage.feature
build/integration/features/sharing-v1.feature
lib/private/Files/Cache/Cache.php

index bc10ddbd94f0144e4e6351a331d4af4d5fda51c1..000cbf1baa5409db464e43f807794c0c2e1053c2 100644 (file)
@@ -71,14 +71,6 @@ class Cache extends CacheJail {
                return $this->cache;
        }
 
-       public function getNumericStorageId() {
-               if (isset($this->numericId)) {
-                       return $this->numericId;
-               } else {
-                       return false;
-               }
-       }
-
        public function get($file) {
                if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
                        return $this->formatCacheEntry(clone $this->sourceRootInfo);
index ae0247a84e26af7da8a118a67e274965af1c85cf..10db4104aae80107624159de4a51828283397083 100644 (file)
@@ -525,4 +525,28 @@ class CacheTest extends TestCase {
                $this->assertEquals('', $sharedCache->getPathById($folderInfo->getId()));
                $this->assertEquals('bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
        }
+
+       public function testNumericStorageId() {
+               self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
+               \OC\Files\Filesystem::mkdir('foo');
+
+               $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+               $node = $rootFolder->get('foo');
+               $share = $this->shareManager->newShare();
+               $share->setNode($node)
+                       ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+                       ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
+                       ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
+                       ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+               $this->shareManager->createShare($share);
+               \OC_Util::tearDownFS();
+
+               list($sourceStorage) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo');
+
+               self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
+               $this->assertTrue(\OC\Files\Filesystem::file_exists('/foo'));
+               list($sharedStorage) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
+
+               $this->assertEquals($sourceStorage->getCache()->getNumericStorageId(), $sharedStorage->getCache()->getNumericStorageId());
+       }
 }
index da085d9e983253e10481dae3bf744298a708a57d..09ffdb2980311965b703e7c8d2f7461ab3676bda 100644 (file)
@@ -23,7 +23,6 @@ Feature: external-storage
       | token | A_TOKEN |
       | mimetype | httpd/unix-directory |
 
-  @local_storage
   Scenario: Shares dont overwrite external storages
     Given user "user0" exists
     And user "user1" exists
@@ -40,3 +39,23 @@ Feature: external-storage
     And folder "/test" of user "user1" is shared with user "user0"
     And As an "user0"
     Then as "user0" the file "/test/textfile1.txt" does not exist
+
+  Scenario: Move a file into storage works
+    Given user "user0" exists
+    And user "user1" exists
+    And As an "user0"
+    And user "user0" created a folder "/local_storage/foo1"
+    When User "user0" moved file "/textfile0.txt" to "/local_storage/foo1/textfile0.txt"
+    Then as "user1" the file "/local_storage/foo1/textfile0.txt" exists
+    And as "user0" the file "/local_storage/foo1/textfile0.txt" exists
+
+  Scenario: Move a file out of the storage works
+    Given user "user0" exists
+    And user "user1" exists
+    And As an "user0"
+    And user "user0" created a folder "/local_storage/foo2"
+    And User "user0" moved file "/textfile0.txt" to "/local_storage/foo2/textfile0.txt"
+    When User "user1" moved file "/local_storage/foo2/textfile0.txt" to "/local.txt"
+    Then as "user1" the file "/local_storage/foo2/textfile0.txt" does not exist
+    And as "user0" the file "/local_storage/foo2/textfile0.txt" does not exist
+    And as "user1" the file "/local.txt" exists
index 4ce32654ba43b7c50782ed48dcc474e244c111bc..74579f635271c95f68725eacdc30e62c7cae3bda 100644 (file)
@@ -988,3 +988,13 @@ Feature: sharing
     And Updating last share with
       | publicUpload | true |
     Then the OCS status code should be "404"
+
+  Scenario: moving a file into a share as recipient
+    Given As an "admin"
+    And user "user0" exists
+    And user "user1" exists
+    And user "user0" created a folder "/shared"
+    And folder "/shared" of user "user0" is shared with user "user1"
+    When User "user1" moved file "/textfile0.txt" to "/shared/shared_file.txt"
+    Then as "user1" the file "/shared/shared_file.txt" exists
+    And as "user0" the file "/shared/shared_file.txt" exists
index 9c3b786ae87fe8ec96de9b1aaeb58d11d22aef21..dfe368d9d220fe161e96dc55639adeec67377c95 100644 (file)
@@ -500,6 +500,7 @@ class Cache implements ICache {
         * @param string $sourcePath
         * @param string $targetPath
         * @throws \OC\DatabaseException
+        * @throws \Exception if the given storages have an invalid id
         */
        public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
                if ($sourceCache instanceof Cache) {
@@ -514,6 +515,13 @@ class Cache implements ICache {
                        list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath);
                        list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath);
 
+                       if (is_null($sourceStorageId) || $sourceStorageId === false) {
+                               throw new \Exception('Invalid source storage id: ' . $sourceStorageId);
+                       }
+                       if (is_null($targetStorageId) || $targetStorageId === false) {
+                               throw new \Exception('Invalid target storage id: ' . $targetStorageId);
+                       }
+
                        // sql for final update
                        $moveSql = 'UPDATE `*PREFIX*filecache` SET `storage` =  ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?';