diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2015-09-22 11:18:42 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2015-09-22 11:32:10 +0200 |
commit | 17a64360e53798cdc6c6479aa40643c8aeb4ff3e (patch) | |
tree | 662081b988f2214dff44f46120dc2fe4d89c8625 /tests | |
parent | 67231ed9a75eafe5b417e4525e3d80b1a3f8826b (diff) | |
download | nextcloud-server-17a64360e53798cdc6c6479aa40643c8aeb4ff3e.tar.gz nextcloud-server-17a64360e53798cdc6c6479aa40643c8aeb4ff3e.zip |
catch excexptions during the copy operation and make sure that we free the lock correctly
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/view.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index bb42f385fc5..618f29fc6f2 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() { |