From 6a19c400fdcc30671ec260fc853bf1a4930ccb7d Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 16 Feb 2017 11:47:16 +0100 Subject: [PATCH] Remove SharedCache::getNumericStorageId to let CacheWrapper do it The CacheWrapper will properly forward the call to the wrapped cache. --- apps/files_sharing/lib/cache.php | 8 ------- apps/files_sharing/tests/cache.php | 24 +++++++++++++++++++ .../features/external-storage.feature | 23 ++++++++++++++++++ build/integration/features/sharing-v1.feature | 10 ++++++++ build/integration/run.sh | 3 +++ lib/private/files/cache/cache.php | 8 +++++++ 6 files changed, 68 insertions(+), 8 deletions(-) diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 4dcdaa892ad7..4754dd73da3d 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -71,14 +71,6 @@ public function __construct($storage, IStorage $sourceStorage, ICacheEntry $sour ); } - public function getNumericStorageId() { - if (isset($this->numericId)) { - return $this->numericId; - } else { - return false; - } - } - protected function formatCacheEntry($entry) { $path = $entry['path']; $entry = parent::formatCacheEntry($entry); diff --git a/apps/files_sharing/tests/cache.php b/apps/files_sharing/tests/cache.php index c137ba0728d9..4dfed60566de 100644 --- a/apps/files_sharing/tests/cache.php +++ b/apps/files_sharing/tests/cache.php @@ -505,4 +505,28 @@ public function testGetPathByIdShareSubFolder() { $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()); + } } diff --git a/build/integration/features/external-storage.feature b/build/integration/features/external-storage.feature index 7fbdf828fb88..48e02ef048e9 100644 --- a/build/integration/features/external-storage.feature +++ b/build/integration/features/external-storage.feature @@ -23,4 +23,27 @@ Feature: external-storage | token | A_TOKEN | | mimetype | httpd/unix-directory | + @local_storage + @no_encryption + 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 + + @local_storage + @no_encryption + 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 diff --git a/build/integration/features/sharing-v1.feature b/build/integration/features/sharing-v1.feature index 65631a3e2ca6..fa34edc4b891 100644 --- a/build/integration/features/sharing-v1.feature +++ b/build/integration/features/sharing-v1.feature @@ -977,3 +977,13 @@ Feature: sharing And the HTTP status code should be "200" And last share_id is not included in the answer + 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 + diff --git a/build/integration/run.sh b/build/integration/run.sh index 2fe0eb1dda58..5e971f7c18fa 100755 --- a/build/integration/run.sh +++ b/build/integration/run.sh @@ -88,6 +88,9 @@ $OCC files_external:delete -y $ID_STORAGE #Disable external storage app $OCC app:disable files_external +# Clear storage folder +rm -Rf work/local_storage/* + if test "$OC_TEST_ALT_HOME" = "1"; then env_alt_home_clear fi diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index c16393cf42eb..a678d92bef38 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -491,6 +491,7 @@ protected function getMoveInfo($path) { * @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) { @@ -505,6 +506,13 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { 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` = ?';