/** * Test rename operation: unlock first path when second path was locked */ public function testLockFileRenameUnlockOnException() { $this->loginAsUser('test'); $view = new \OC\Files\View('/' . $this->user . '/files/'); $sourcePath = 'original.txt'; $targetPath = 'target.txt'; $view->file_put_contents($sourcePath, 'meh'); // simulate that the target path is already locked $view->lockFile($targetPath, ILockingProvider::LOCK_EXCLUSIVE); $this->assertNull($this->getFileLockType($view, $sourcePath), 'Source file not locked before operation'); $this->assertEquals(ILockingProvider::LOCK_EXCLUSIVE, $this->getFileLockType($view, $targetPath), 'Target file is locked before operation'); $thrown = false; try { $view->rename($sourcePath, $targetPath); } catch (\OCP\Lock\LockedException $e) { $thrown = true; } $this->assertTrue($thrown, 'LockedException thrown'); $this->assertNull($this->getFileLockType($view, $sourcePath), 'Source file not locked after operation'); $this->assertEquals(ILockingProvider::LOCK_EXCLUSIVE, $this->getFileLockType($view, $targetPath), 'Target file still locked after operation'); $view->unlockFile($targetPath, ILockingProvider::LOCK_EXCLUSIVE); }
/** * 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'); }
/** * e.g. writing a file that's being downloaded * * @expectedException \OCP\Lock\LockedException */ public function testWriteToReadLockedFile() { $view = new \OC\Files\View(); $storage = new Temporary(array()); \OC\Files\Filesystem::mount($storage, [], '/'); $view->lockFile('/foo/bar', ILockingProvider::LOCK_SHARED); $view->lockFile('/foo/bar', ILockingProvider::LOCK_EXCLUSIVE); }
public function testChangeLock() { $view = new \OC\Files\View('/testuser/files/'); $storage = new Temporary(array()); \OC\Files\Filesystem::mount($storage, [], '/'); $view->lockFile('/test/sub', ILockingProvider::LOCK_SHARED); $this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED)); $this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE)); $view->changeLock('//test/sub', ILockingProvider::LOCK_EXCLUSIVE); $this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE)); $view->changeLock('test/sub', ILockingProvider::LOCK_SHARED); $this->assertTrue($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED)); $view->unlockFile('/test/sub/', ILockingProvider::LOCK_SHARED); $this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_SHARED)); $this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE)); }