/** * Test exception during final rename in chunk upload mode */ public function testChunkedPutFailsFinalRename() { $view = new \OC\Files\View('/' . $this->user . '/files'); // simulate situation where the target file is locked $view->lockFile('/test.txt', ILockingProvider::LOCK_EXCLUSIVE); $_SERVER['HTTP_OC_CHUNKED'] = true; $info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-0', null, null, ['permissions' => \OCP\Constants::PERMISSION_ALL], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); $file->acquireLock(ILockingProvider::LOCK_SHARED); $this->assertNull($file->put('test data one')); $file->releaseLock(ILockingProvider::LOCK_SHARED); $info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-1', null, null, ['permissions' => \OCP\Constants::PERMISSION_ALL], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); // action $thrown = false; try { $file->acquireLock(ILockingProvider::LOCK_SHARED); $file->put($this->getStream('test data')); $file->releaseLock(ILockingProvider::LOCK_SHARED); } catch (\OCA\DAV\Connector\Sabre\Exception\FileLocked $e) { $thrown = true; } $this->assertTrue($thrown); $this->assertEmpty($this->listPartFiles($view, ''), 'No stray part files'); }
/** * Test putting a file using chunking * * @dataProvider fopenFailuresProvider */ public function testChunkedPutFails($thrownException, $expectedException, $checkPreviousClass = false) { // setup $storage = $this->getMock('\\OC\\Files\\Storage\\Local', ['fopen'], [['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]]); \OC\Files\Filesystem::mount($storage, [], $this->user . '/'); $view = $this->getMock('\\OC\\Files\\View', ['getRelativePath', 'resolvePath'], []); $view->expects($this->atLeastOnce())->method('resolvePath')->will($this->returnCallback(function ($path) use($storage) { return [$storage, $path]; })); if ($thrownException !== null) { $storage->expects($this->once())->method('fopen')->will($this->throwException($thrownException)); } else { $storage->expects($this->once())->method('fopen')->will($this->returnValue(false)); } $view->expects($this->any())->method('getRelativePath')->will($this->returnArgument(0)); $_SERVER['HTTP_OC_CHUNKED'] = true; $info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-0', null, null, ['permissions' => \OCP\Constants::PERMISSION_ALL], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); // put first chunk $this->assertNull($file->put('test data one')); $info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-1', null, null, ['permissions' => \OCP\Constants::PERMISSION_ALL], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); // action $caughtException = null; try { // last chunk $file->acquireLock(ILockingProvider::LOCK_SHARED); $file->put('test data two'); $file->releaseLock(ILockingProvider::LOCK_SHARED); } catch (\Exception $e) { $caughtException = $e; } $this->assertInstanceOf($expectedException, $caughtException); if ($checkPreviousClass) { $this->assertInstanceOf(get_class($thrownException), $caughtException->getPrevious()); } $this->assertEmpty($this->listPartFiles($view, ''), 'No stray part files'); }