From b70e1ffc6d91a4ca2c6b66012ea6f7e5d39050a0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 13 May 2015 14:09:07 +0200 Subject: [PATCH 1/7] dont go trough the view when moving to trash --- apps/files_trashbin/lib/trashbin.php | 39 +++++++++++++++++++--------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 31d77c01c9..9c8aa5e752 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -184,22 +184,27 @@ class Trashbin { // disable proxy to prevent recursive calls $trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp; + + /** @var \OC\Files\Storage\Storage $trashStorage */ + list($trashStorage, $trashInternalPath) = $view->resolvePath($trashPath); + /** @var \OC\Files\Storage\Storage $sourceStorage */ + list($sourceStorage, $sourceInternalPath) = $view->resolvePath('/files/' . $file_path); try { - $sizeOfAddedFiles = $view->filesize('/files/' . $file_path); - if ($view->file_exists($trashPath)) { - $view->unlink($trashPath); + $sizeOfAddedFiles = $sourceStorage->filesize($sourceInternalPath); + if ($trashStorage->file_exists($trashInternalPath)) { + $trashStorage->unlink($trashInternalPath); } - $view->rename('/files/' . $file_path, $trashPath); + $trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath); } catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) { $sizeOfAddedFiles = false; - if ($view->file_exists($trashPath)) { - $view->deleteAll($trashPath); + if ($trashStorage->file_exists($trashInternalPath)) { + $trashStorage->unlink($trashInternalPath); } \OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR); } - if ($view->file_exists('/files/' . $file_path)) { // failed to delete the original file, abort - $view->unlink($trashPath); + if ($sourceStorage->file_exists($sourceInternalPath)) { // failed to delete the original file, abort + $sourceStorage->unlink($sourceInternalPath); return false; } @@ -257,18 +262,28 @@ class Trashbin { } if ($rootView->is_dir($owner . '/files_versions/' . $ownerPath)) { + /** @var \OC\Files\Storage\Storage $versionStorage */ + list($versionStorage, $versionsInternalPath) = $rootView->resolvePath($owner . '/files_versions/' . $ownerPath); + /** @var \OC\Files\Storage\Storage $trashStorage */ + list($trashStorage, $trashInternalPath) = $rootView->resolvePath($user . '/files_trashbin/versions/' . $filename . '.d' . $timestamp); + $size += self::calculateSize(new \OC\Files\View('/' . $owner . '/files_versions/' . $ownerPath)); if ($owner !== $user) { self::copy_recursive($owner . '/files_versions/' . $ownerPath, $owner . '/files_trashbin/versions/' . basename($ownerPath) . '.d' . $timestamp, $rootView); } - $rootView->rename($owner . '/files_versions/' . $ownerPath, $user . '/files_trashbin/versions/' . $filename . '.d' . $timestamp); + $trashStorage->moveFromStorage($versionStorage, $versionsInternalPath, $trashInternalPath); } else if ($versions = \OCA\Files_Versions\Storage::getVersions($owner, $ownerPath)) { + /** @var \OC\Files\Storage\Storage $versionStorage */ + list($versionStorage, $versionsInternalPath) = $rootView->resolvePath($owner . '/files_versions/'); + /** @var \OC\Files\Storage\Storage $trashStorage */ + list($trashStorage, $trashInternalPath) = $rootView->resolvePath($user . '/files_trashbin/versions/'); + foreach ($versions as $v) { - $size += $rootView->filesize($owner . '/files_versions' . $v['path'] . '.v' . $v['version']); + $size += $versionStorage->filesize($versionsInternalPath . $v['path'] . '.v' . $v['version']); if ($owner !== $user) { - $rootView->copy($owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $owner . '/files_trashbin/versions/' . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); + $trashStorage->copyFromStorage($versionStorage, $versionsInternalPath . $v['path'] . '.v' . $v['version'], $owner . $trashInternalPath . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); } - $rootView->rename($owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $user . '/files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp); + $trashStorage->moveFromStorage($versionStorage, $versionsInternalPath . $v['path'] . '.v' . $v['version'], $trashInternalPath . $filename . '.v' . $v['version'] . '.d' . $timestamp); } } } From a0854b36f012e4c5573a4ed6ea8d074482908c4b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 13 May 2015 14:54:43 +0200 Subject: [PATCH 2/7] update cache after move to trash --- apps/files_trashbin/lib/trashbin.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 9c8aa5e752..26a7aeb803 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -208,6 +208,8 @@ class Trashbin { return false; } + $view->getUpdater()->rename('/files/' . $file_path, $trashPath); + if ($sizeOfAddedFiles !== false) { $size = $sizeOfAddedFiles; $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)"); From 89959a856c97a7267630a05356aa4f6699e0adc3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 13 May 2015 16:34:22 +0200 Subject: [PATCH 3/7] fix target path for move --- apps/files_trashbin/lib/trashbin.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 26a7aeb803..eeb8c3bb3e 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -279,13 +279,17 @@ class Trashbin { list($versionStorage, $versionsInternalPath) = $rootView->resolvePath($owner . '/files_versions/'); /** @var \OC\Files\Storage\Storage $trashStorage */ list($trashStorage, $trashInternalPath) = $rootView->resolvePath($user . '/files_trashbin/versions/'); + /** @var \OC\Files\Storage\Storage $ownerTrashStorage */ + list($ownerTrashStorage, $ownerTrashInternalPath) = $rootView->resolvePath($owner . '/files_trashbin/versions/'); foreach ($versions as $v) { $size += $versionStorage->filesize($versionsInternalPath . $v['path'] . '.v' . $v['version']); if ($owner !== $user) { - $trashStorage->copyFromStorage($versionStorage, $versionsInternalPath . $v['path'] . '.v' . $v['version'], $owner . $trashInternalPath . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); + $ownerTrashStorage->copyFromStorage($versionStorage, $versionsInternalPath . $v['path'] . '.v' . $v['version'], $ownerTrashInternalPath . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); + $rootView->getUpdater()->update($owner . '/files_trashbin/versions/' . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); } - $trashStorage->moveFromStorage($versionStorage, $versionsInternalPath . $v['path'] . '.v' . $v['version'], $trashInternalPath . $filename . '.v' . $v['version'] . '.d' . $timestamp); + $trashStorage->moveFromStorage($versionStorage, $versionsInternalPath . $v['path'] . '.v' . $v['version'], $trashInternalPath . '/' . $filename . '.v' . $v['version'] . '.d' . $timestamp); + $rootView->getUpdater()->rename($owner . '/files_versions/' . $v['path'] . '.v' . $v['version'], $user . '/files_trashbin/versions/' . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); } } } From 8f1a609512744f38976582e9e31b2c14c8f90d01 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 13 May 2015 16:36:06 +0200 Subject: [PATCH 4/7] adjust test --- apps/files_trashbin/tests/storage.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/files_trashbin/tests/storage.php b/apps/files_trashbin/tests/storage.php index 7415aba09e..e0fdc43830 100644 --- a/apps/files_trashbin/tests/storage.php +++ b/apps/files_trashbin/tests/storage.php @@ -318,9 +318,15 @@ class Storage extends \Test\TestCase { */ $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary') ->setConstructorArgs([[]]) - ->setMethods(['rename', 'unlink']) + ->setMethods(['rename', 'unlink', 'moveFromStorage']) ->getMock(); + $storage->expects($this->any()) + ->method('rename') + ->will($this->returnValue(false)); + $storage->expects($this->any()) + ->method('moveFromStorage') + ->will($this->returnValue(false)); $storage->expects($this->any()) ->method('unlink') ->will($this->returnValue(false)); From 9c751f1d871179523e55f93777a473e808d4441b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 19 May 2015 14:21:58 +0200 Subject: [PATCH 5/7] use copy when doing a crossStorageCopy on the same storage --- lib/private/files/storage/common.php | 15 ++++++++++++--- lib/private/files/storage/wrapper/wrapper.php | 8 ++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index fc30b385e2..893e4ea7d9 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -498,18 +498,18 @@ abstract class Common implements Storage { * @throws InvalidPathException */ private function scanForInvalidCharacters($fileName, $invalidChars) { - foreach(str_split($invalidChars) as $char) { + foreach (str_split($invalidChars) as $char) { if (strpos($fileName, $char) !== false) { throw new InvalidCharacterInPathException(); } } $sanitizedFileName = filter_var($fileName, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW); - if($sanitizedFileName !== $fileName) { + if ($sanitizedFileName !== $fileName) { throw new InvalidCharacterInPathException(); } } - + /** * @param array $options */ @@ -525,6 +525,7 @@ abstract class Common implements Storage { public function getMountOption($name, $default = null) { return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default; } + /** * @param \OCP\Files\Storage $sourceStorage * @param string $sourceInternalPath @@ -533,6 +534,10 @@ abstract class Common implements Storage { * @return bool */ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + if ($sourceStorage === $this) { + return $this->copy($sourceInternalPath, $targetInternalPath); + } + if ($sourceStorage->is_dir($sourceInternalPath)) { $dh = $sourceStorage->opendir($sourceInternalPath); $result = $this->mkdir($targetInternalPath); @@ -575,6 +580,10 @@ abstract class Common implements Storage { * @return bool */ public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + if ($sourceStorage === $this) { + return $this->rename($sourceInternalPath, $targetInternalPath); + } + $result = $this->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, true); if ($result) { if ($sourceStorage->is_dir($sourceInternalPath)) { diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php index f3dc09db13..14024addec 100644 --- a/lib/private/files/storage/wrapper/wrapper.php +++ b/lib/private/files/storage/wrapper/wrapper.php @@ -513,6 +513,10 @@ class Wrapper implements \OC\Files\Storage\Storage { * @return bool */ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + if ($sourceStorage === $this) { + return $this->copy($sourceInternalPath, $targetInternalPath); + } + return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } @@ -523,6 +527,10 @@ class Wrapper implements \OC\Files\Storage\Storage { * @return bool */ public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + if ($sourceStorage === $this) { + return $this->rename($sourceInternalPath, $targetInternalPath); + } + return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } From 733784ae41b67558c86da43f2a0ddbacdcf49e33 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 19 May 2015 14:22:09 +0200 Subject: [PATCH 6/7] cleanup move/copy logic in trash --- apps/files_trashbin/lib/trashbin.php | 77 ++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 20 deletions(-) diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index eeb8c3bb3e..6a1dcf3fce 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -37,6 +37,7 @@ namespace OCA\Files_Trashbin; use OC\Files\Filesystem; +use OC\Files\View; use OCA\Files_Trashbin\Command\Expire; class Trashbin { @@ -124,6 +125,7 @@ class Trashbin { /** * copy file to owners trash + * * @param string $sourcePath * @param string $owner * @param string $ownerPath @@ -264,32 +266,19 @@ class Trashbin { } if ($rootView->is_dir($owner . '/files_versions/' . $ownerPath)) { - /** @var \OC\Files\Storage\Storage $versionStorage */ - list($versionStorage, $versionsInternalPath) = $rootView->resolvePath($owner . '/files_versions/' . $ownerPath); - /** @var \OC\Files\Storage\Storage $trashStorage */ - list($trashStorage, $trashInternalPath) = $rootView->resolvePath($user . '/files_trashbin/versions/' . $filename . '.d' . $timestamp); - $size += self::calculateSize(new \OC\Files\View('/' . $owner . '/files_versions/' . $ownerPath)); if ($owner !== $user) { self::copy_recursive($owner . '/files_versions/' . $ownerPath, $owner . '/files_trashbin/versions/' . basename($ownerPath) . '.d' . $timestamp, $rootView); } - $trashStorage->moveFromStorage($versionStorage, $versionsInternalPath, $trashInternalPath); + self::move($rootView, $owner . '/files_versions/' . $ownerPath, $user . '/files_trashbin/versions/' . $filename . '.d' . $timestamp); } else if ($versions = \OCA\Files_Versions\Storage::getVersions($owner, $ownerPath)) { - /** @var \OC\Files\Storage\Storage $versionStorage */ - list($versionStorage, $versionsInternalPath) = $rootView->resolvePath($owner . '/files_versions/'); - /** @var \OC\Files\Storage\Storage $trashStorage */ - list($trashStorage, $trashInternalPath) = $rootView->resolvePath($user . '/files_trashbin/versions/'); - /** @var \OC\Files\Storage\Storage $ownerTrashStorage */ - list($ownerTrashStorage, $ownerTrashInternalPath) = $rootView->resolvePath($owner . '/files_trashbin/versions/'); foreach ($versions as $v) { - $size += $versionStorage->filesize($versionsInternalPath . $v['path'] . '.v' . $v['version']); + $size += $rootView->filesize($owner . '/files_versions/' . $v['path'] . '.v' . $v['version']); if ($owner !== $user) { - $ownerTrashStorage->copyFromStorage($versionStorage, $versionsInternalPath . $v['path'] . '.v' . $v['version'], $ownerTrashInternalPath . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); - $rootView->getUpdater()->update($owner . '/files_trashbin/versions/' . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); + self::copy($rootView, $owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $owner . '/files_trashbin/versions/' . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); } - $trashStorage->moveFromStorage($versionStorage, $versionsInternalPath . $v['path'] . '.v' . $v['version'], $trashInternalPath . '/' . $filename . '.v' . $v['version'] . '.d' . $timestamp); - $rootView->getUpdater()->rename($owner . '/files_versions/' . $v['path'] . '.v' . $v['version'], $user . '/files_trashbin/versions/' . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); + self::move($rootView, $owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $user . '/files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp); } } } @@ -297,6 +286,50 @@ class Trashbin { return $size; } + /** + * Move a file or folder on storage level + * + * @param View $view + * @param string $source + * @param string $target + * @return bool + */ + private static function move(View $view, $source, $target) { + /** @var \OC\Files\Storage\Storage $sourceStorage */ + list($sourceStorage, $sourceInternalPath) = $view->resolvePath($source); + /** @var \OC\Files\Storage\Storage $targetStorage */ + list($targetStorage, $targetInternalPath) = $view->resolvePath($target); + /** @var \OC\Files\Storage\Storage $ownerTrashStorage */ + + $result = $targetStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + if ($result) { + $view->getUpdater()->rename($source, $target); + } + return $result; + } + + /** + * Copy a file or folder on storage level + * + * @param View $view + * @param string $source + * @param string $target + * @return bool + */ + private static function copy(View $view, $source, $target) { + /** @var \OC\Files\Storage\Storage $sourceStorage */ + list($sourceStorage, $sourceInternalPath) = $view->resolvePath($source); + /** @var \OC\Files\Storage\Storage $targetStorage */ + list($targetStorage, $targetInternalPath) = $view->resolvePath($target); + /** @var \OC\Files\Storage\Storage $ownerTrashStorage */ + + $result = $targetStorage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + if ($result) { + $view->getUpdater()->update($target); + } + return $result; + } + /** * Restore a file or folder from trash bin * @@ -320,7 +353,7 @@ class Trashbin { // if location no longer exists, restore file in the root directory if ($location !== '/' && (!$view->is_dir('files/' . $location) || - !$view->isCreatable('files/' . $location)) + !$view->isCreatable('files/' . $location)) ) { $location = ''; } @@ -590,6 +623,7 @@ class Trashbin { /** * resize trash bin if necessary after a new file was added to ownCloud + * * @param string $user user id */ public static function resizeTrash($user) { @@ -644,6 +678,7 @@ class Trashbin { /** * if the size limit for the trash bin is reached, we delete the oldest * files in the trash bin until we meet the limit again + * * @param array $files * @param string $user * @param int $availableSpace available disc space @@ -746,7 +781,7 @@ class Trashbin { //force rescan of versions, local storage may not have updated the cache if (!self::$scannedVersions) { /** @var \OC\Files\Storage\Storage $storage */ - list($storage, ) = $view->resolvePath('/'); + list($storage,) = $view->resolvePath('/'); $storage->getScanner()->scan('files_trashbin/versions'); self::$scannedVersions = true; } @@ -809,6 +844,7 @@ class Trashbin { /** * get the size from a given root folder + * * @param \OC\Files\View $view file view on the root folder * @return integer size of the folder */ @@ -820,7 +856,7 @@ class Trashbin { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root), \RecursiveIteratorIterator::CHILD_FIRST); $size = 0; - /** + /** * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach * This bug is fixed in PHP 5.5.9 or before * See #8376 @@ -866,6 +902,7 @@ class Trashbin { /** * check if trash bin is empty for a given user + * * @param string $user * @return bool */ From 2213d6597c5d052acc27e294227a10d23ba00448 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 19 May 2015 17:30:32 +0200 Subject: [PATCH 7/7] add tests for copyFromStorage with same storage --- tests/lib/files/storage/storage.php | 37 +++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 938fecb5bf..e8602b6b24 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -176,7 +176,7 @@ abstract class Storage extends \Test\TestCase { ]; } - public function initSourceAndTarget ($source, $target = null) { + public function initSourceAndTarget($source, $target = null) { $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; $this->instance->file_put_contents($source, file_get_contents($textFile)); if ($target) { @@ -185,12 +185,12 @@ abstract class Storage extends \Test\TestCase { } } - public function assertSameAsLorem ($file) { + public function assertSameAsLorem($file) { $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; $this->assertEquals( file_get_contents($textFile), $this->instance->file_get_contents($file), - 'Expected '.$file.' to be a copy of '.$textFile + 'Expected ' . $file . ' to be a copy of ' . $textFile ); } @@ -202,9 +202,9 @@ abstract class Storage extends \Test\TestCase { $this->instance->copy($source, $target); - $this->assertTrue($this->instance->file_exists($target), $target.' was not created'); + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); $this->assertSameAsLorem($target); - $this->assertTrue($this->instance->file_exists($source), $source.' was deleted'); + $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); } /** @@ -216,8 +216,8 @@ abstract class Storage extends \Test\TestCase { $this->instance->rename($source, $target); $this->wait(); - $this->assertTrue($this->instance->file_exists($target), $target.' was not created'); - $this->assertFalse($this->instance->file_exists($source), $source.' still exists'); + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); + $this->assertFalse($this->instance->file_exists($source), $source . ' still exists'); $this->assertSameAsLorem($target); } @@ -225,12 +225,12 @@ abstract class Storage extends \Test\TestCase { * @dataProvider copyAndMoveProvider */ public function testCopyOverwrite($source, $target) { - $this->initSourceAndTarget($source,$target); + $this->initSourceAndTarget($source, $target); $this->instance->copy($source, $target); - $this->assertTrue($this->instance->file_exists($target), $target.' was not created'); - $this->assertTrue($this->instance->file_exists($source), $source.' was deleted'); + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); + $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); $this->assertSameAsLorem($target); $this->assertSameAsLorem($source); } @@ -243,8 +243,8 @@ abstract class Storage extends \Test\TestCase { $this->instance->rename($source, $target); - $this->assertTrue($this->instance->file_exists($target), $target.' was not created'); - $this->assertFalse($this->instance->file_exists($source), $source.' still exists'); + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); + $this->assertFalse($this->instance->file_exists($source), $source . ' still exists'); $this->assertSameAsLorem($target); } @@ -535,4 +535,17 @@ abstract class Storage extends \Test\TestCase { $this->assertTrue($this->instance->instanceOfStorage(get_class($this->instance))); $this->assertFalse($this->instance->instanceOfStorage('\OC')); } + + /** + * @dataProvider copyAndMoveProvider + */ + public function testCopyFromSameStorage($source, $target) { + $this->initSourceAndTarget($source); + + $this->instance->copyFromStorage($this->instance, $source, $target); + + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); + $this->assertSameAsLorem($target); + $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); + } }