diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-04-14 14:35:08 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-04-14 14:35:08 +0200 |
commit | 82cab257622759d1b64582f27de33a982c79c158 (patch) | |
tree | bcacfc55a044830e1a5529b9bece572bb6f180e8 /apps | |
parent | ffa115b51725c4774b49c2419f88cb91d726386b (diff) | |
parent | 0f21303b751291188733e24b5f213053ea96a368 (diff) | |
download | nextcloud-server-82cab257622759d1b64582f27de33a982c79c158.tar.gz nextcloud-server-82cab257622759d1b64582f27de33a982c79c158.zip |
Merge pull request #13360 from owncloud/cross-storage-move
Proper copy/move between multiple local storages
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/lib/sharedstorage.php | 34 | ||||
-rw-r--r-- | apps/files_sharing/tests/sharedstorage.php | 70 | ||||
-rw-r--r-- | apps/files_trashbin/tests/storage.php | 9 |
3 files changed, 103 insertions, 10 deletions
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index c2253fcaa3c..8c2f03b1419 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -586,4 +586,38 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage { return $result; } + /** + * Resolve the path for the source of the share + * + * @param string $path + * @return array + */ + private function resolvePath($path) { + $source = $this->getSourcePath($path); + return \OC\Files\Filesystem::resolvePath($source); + } + + /** + * @param \OCP\Files\Storage $sourceStorage + * @param string $sourceInternalPath + * @param string $targetInternalPath + * @return bool + */ + public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + /** @var \OCP\Files\Storage $targetStorage */ + list($targetStorage, $targetInternalPath) = $this->resolvePath($targetInternalPath); + return $targetStorage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + } + + /** + * @param \OCP\Files\Storage $sourceStorage + * @param string $sourceInternalPath + * @param string $targetInternalPath + * @return bool + */ + public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + /** @var \OCP\Files\Storage $targetStorage */ + list($targetStorage, $targetInternalPath) = $this->resolvePath($targetInternalPath); + return $targetStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + } } diff --git a/apps/files_sharing/tests/sharedstorage.php b/apps/files_sharing/tests/sharedstorage.php index a8ce92775d6..a1469a74687 100644 --- a/apps/files_sharing/tests/sharedstorage.php +++ b/apps/files_sharing/tests/sharedstorage.php @@ -117,21 +117,21 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase { $this->assertTrue($user2View->file_exists($this->folder)); // create part file - $result = $user2View->file_put_contents($this->folder. '/foo.txt.part', 'some test data'); + $result = $user2View->file_put_contents($this->folder . '/foo.txt.part', 'some test data'); $this->assertTrue(is_int($result)); // rename part file to real file - $result = $user2View->rename($this->folder. '/foo.txt.part', $this->folder. '/foo.txt'); + $result = $user2View->rename($this->folder . '/foo.txt.part', $this->folder . '/foo.txt'); $this->assertTrue($result); // check if the new file really exists - $this->assertTrue($user2View->file_exists( $this->folder. '/foo.txt')); + $this->assertTrue($user2View->file_exists($this->folder . '/foo.txt')); // check if the rename also affected the owner self::loginHelper(self::TEST_FILES_SHARING_API_USER1); - $this->assertTrue($this->view->file_exists( $this->folder. '/foo.txt')); + $this->assertTrue($this->view->file_exists($this->folder . '/foo.txt')); //cleanup \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, @@ -144,7 +144,7 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase { $fileinfoFile = $this->view->getFileInfo($this->filename); $folderSize = $this->view->filesize($this->folder); - $file1Size = $this->view->filesize($this->folder. $this->filename); + $file1Size = $this->view->filesize($this->folder . $this->filename); $file2Size = $this->view->filesize($this->filename); $result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, @@ -373,11 +373,69 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase { $this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER3 . '/files/' . $this->filename)); // make sure we didn't double setup shares for user 2 or mounted the shares for user 3 in user's 2 home - $this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder .' (2)')); + $this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder . ' (2)')); $this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->filename)); //cleanup self::loginHelper(self::TEST_FILES_SHARING_API_USER1); $this->view->unlink($this->folder); } + + public function testCopyFromStorage() { + $folderInfo = $this->view->getFileInfo($this->folder); + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + + // share 2 different files with 2 different users + \OCP\Share::shareItem('folder', $folderInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2, 31); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); + $this->assertTrue($view->file_exists($this->folder)); + + /** + * @var \OCP\Files\Storage $sharedStorage + */ + list($sharedStorage,) = $view->resolvePath($this->folder); + $this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')); + + $sourceStorage = new \OC\Files\Storage\Temporary(array()); + $sourceStorage->file_put_contents('foo.txt', 'asd'); + + $sharedStorage->copyFromStorage($sourceStorage, 'foo.txt', 'bar.txt'); + $this->assertTrue($sharedStorage->file_exists('bar.txt')); + $this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt')); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + $this->view->unlink($this->folder); + } + + public function testMoveFromStorage() { + $folderInfo = $this->view->getFileInfo($this->folder); + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + + // share 2 different files with 2 different users + \OCP\Share::shareItem('folder', $folderInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2, 31); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); + $this->assertTrue($view->file_exists($this->folder)); + + /** + * @var \OCP\Files\Storage $sharedStorage + */ + list($sharedStorage,) = $view->resolvePath($this->folder); + $this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')); + + $sourceStorage = new \OC\Files\Storage\Temporary(array()); + $sourceStorage->file_put_contents('foo.txt', 'asd'); + + $sharedStorage->moveFromStorage($sourceStorage, 'foo.txt', 'bar.txt'); + $this->assertTrue($sharedStorage->file_exists('bar.txt')); + $this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt')); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + $this->view->unlink($this->folder); + } } diff --git a/apps/files_trashbin/tests/storage.php b/apps/files_trashbin/tests/storage.php index d5bd7c318d3..d1468522dc2 100644 --- a/apps/files_trashbin/tests/storage.php +++ b/apps/files_trashbin/tests/storage.php @@ -202,12 +202,13 @@ class Storage extends \Test\TestCase { $cache = $storage->getCache(); - Filesystem::mount($storage, [], '/' . $this->user . '/files'); + Filesystem::mount($storage, [], '/' . $this->user); + $storage->mkdir('files'); $this->userView->file_put_contents('test.txt', 'foo'); - $this->assertTrue($storage->file_exists('test.txt')); + $this->assertTrue($storage->file_exists('files/test.txt')); $this->assertFalse($this->userView->unlink('test.txt')); - $this->assertTrue($storage->file_exists('test.txt')); - $this->assertTrue($cache->inCache('test.txt')); + $this->assertTrue($storage->file_exists('files/test.txt')); + $this->assertTrue($cache->inCache('files/test.txt')); // file should not be in the trashbin $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/'); |