Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-09-23 12:28:27 +0300
committerThomas Müller <thomas.mueller@tmit.eu>2015-09-23 12:28:27 +0300
commitad71d92acf0ce9a5a3e29cc61ab1c73d2c25368b (patch)
tree8539f08100ae07c5b4ca6a362fe4c4b8f14b3379 /tests
parentf3d60df56dec22d2f2f39920c0a93913a9040dad (diff)
parent17a64360e53798cdc6c6479aa40643c8aeb4ff3e (diff)
Merge pull request #19247 from owncloud/fix_locking_copy_operation
locking: handle exceptions correctly during copy operation
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/view.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index abb1696ae70..83f53833855 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -1818,6 +1818,49 @@ class View extends \Test\TestCase {
}
/**
+ * simulate a failed copy operation.
+ * We expect that we catch the exception, free the lock and re-throw it.
+ *
+ * @expectedException \Exception
+ */
+ public function testLockFileCopyException() {
+ $view = new \OC\Files\View('/' . $this->user . '/files/');
+
+ $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
+ ->setMethods(['copy'])
+ ->getMock();
+
+ $sourcePath = 'original.txt';
+ $targetPath = 'target.txt';
+
+ \OC\Files\Filesystem::mount($storage, array(), $this->user . '/');
+ $storage->mkdir('files');
+ $view->file_put_contents($sourcePath, 'meh');
+
+ $storage->expects($this->once())
+ ->method('copy')
+ ->will($this->returnCallback(
+ function() {
+ throw new \Exception();
+ }
+ ));
+
+ $this->connectMockHooks('copy', $view, $sourcePath, $lockTypeSourcePre, $lockTypeSourcePost);
+ $this->connectMockHooks('copy', $view, $targetPath, $lockTypeTargetPre, $lockTypeTargetPost);
+
+ $this->assertNull($this->getFileLockType($view, $sourcePath), 'Source file not locked before operation');
+ $this->assertNull($this->getFileLockType($view, $targetPath), 'Target file not locked before operation');
+
+ try {
+ $view->copy($sourcePath, $targetPath);
+ } catch (\Exception $e) {
+ $this->assertNull($this->getFileLockType($view, $sourcePath), 'Source file not locked after operation');
+ $this->assertNull($this->getFileLockType($view, $targetPath), 'Target file not locked after operation');
+ throw $e;
+ }
+ }
+
+ /**
* Test rename operation: unlock first path when second path was locked
*/
public function testLockFileRenameUnlockOnException() {