Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SharedCache::getNumericStorageId to let CacheWrapper do it #4004

Merged
merged 3 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions apps/files_sharing/lib/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ public function getCache() {
return $this->cache;
}

public function getNumericStorageId() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this breaks the sharing performance improvements

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);
Expand Down
24 changes: 24 additions & 0 deletions apps/files_sharing/tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,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());
}
}
21 changes: 20 additions & 1 deletion build/integration/features/external-storage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 10 additions & 0 deletions build/integration/features/sharing-v1.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,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) {
Expand All @@ -514,6 +515,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` = ?';

Expand Down