public function viewToNodeProvider() { return [[function () { Filesystem::file_put_contents('test.txt', 'asd'); }, 'preWrite'], [function () { Filesystem::file_put_contents('test.txt', 'asd'); }, 'postWrite'], [function () { Filesystem::file_put_contents('test.txt', 'asd'); }, 'preCreate'], [function () { Filesystem::file_put_contents('test.txt', 'asd'); }, 'postCreate'], [function () { Filesystem::mkdir('test.txt'); }, 'preCreate'], [function () { Filesystem::mkdir('test.txt'); }, 'postCreate'], [function () { Filesystem::touch('test.txt'); }, 'preTouch'], [function () { Filesystem::touch('test.txt'); }, 'postTouch'], [function () { Filesystem::touch('test.txt'); }, 'preCreate'], [function () { Filesystem::touch('test.txt'); }, 'postCreate'], [function () { Filesystem::file_put_contents('test.txt', 'asd'); Filesystem::unlink('test.txt'); }, 'preDelete'], [function () { Filesystem::file_put_contents('test.txt', 'asd'); Filesystem::unlink('test.txt'); }, 'postDelete'], [function () { Filesystem::mkdir('test.txt'); Filesystem::rmdir('test.txt'); }, 'preDelete'], [function () { Filesystem::mkdir('test.txt'); Filesystem::rmdir('test.txt'); }, 'postDelete']]; }
public function testDelete() { $textSize = strlen("dummy file data\n"); $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png'); $rootCachedData = $this->cache->get(''); $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']); $this->assertTrue($this->cache->inCache('foo.txt')); Filesystem::unlink('foo.txt'); $this->assertFalse($this->cache->inCache('foo.txt')); $cachedData = $this->cache->get(''); $this->assertEquals(2 * $textSize + $imageSize, $cachedData['size']); $this->assertInternalType('string', $rootCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']); $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']); $rootCachedData = $cachedData; Filesystem::mkdir('bar_folder'); $this->assertTrue($this->cache->inCache('bar_folder')); $cachedData = $this->cache->get(''); $this->assertInternalType('string', $rootCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']); $rootCachedData = $cachedData; Filesystem::rmdir('bar_folder'); $this->assertFalse($this->cache->inCache('bar_folder')); $cachedData = $this->cache->get(''); $this->assertInternalType('string', $rootCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']); $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']); }
/** * If the permissions on a group share are upgraded be sure to still respect * removed shares by a member of that group */ function testPermissionUpgradeOnUserDeletedGroupShare() { \OC_Group::createGroup('testGroup'); \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup'); \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup'); \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup'); $connection = \OC::$server->getDatabaseConnection(); // Share item with group $fileinfo = $this->view->getFileInfo($this->folder); $share = $this->share(\OCP\Share::SHARE_TYPE_GROUP, $this->folder, self::TEST_FILES_SHARING_API_USER1, 'testGroup', \OCP\Constants::PERMISSION_READ); // Login as user 2 and verify the item exists self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder)); $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2); $this->assertNotEmpty($result); $this->assertEquals(\OCP\Constants::PERMISSION_READ, $result->getPermissions()); // Delete the share $this->assertTrue(\OC\Files\Filesystem::rmdir($this->folder)); $this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder)); // Verify we do not get a share $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2); $this->assertEquals(0, $result->getPermissions()); // Login as user 1 again and change permissions self::loginHelper(self::TEST_FILES_SHARING_API_USER1); $share->setPermissions(\OCP\Constants::PERMISSION_ALL); $share = $this->shareManager->updateShare($share); // Login as user 2 and verify self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder)); $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2); $this->assertEquals(0, $result->getPermissions()); $this->shareManager->deleteShare($share); //cleanup self::loginHelper(self::TEST_FILES_SHARING_API_USER1); \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup'); \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup'); \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup'); }
/** * Deletes all files in this directory, and then itself * * @return void * @throws Sabre_DAV_Exception_Forbidden */ public function delete() { if ($this->path === 'Shared') { throw new \Sabre_DAV_Exception_Forbidden(); } if (!\OC\Files\Filesystem::isDeletable($this->path)) { throw new \Sabre_DAV_Exception_Forbidden(); } \OC\Files\Filesystem::rmdir($this->path); }
/** * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem */ public static function rmdir($path) { return \OC\Files\Filesystem::rmdir($path); }
/** * If the permissions on a group share are upgraded be sure to still respect * removed shares by a member of that group */ function testPermissionUpgradeOnUserDeletedGroupShare() { \OC_Group::createGroup('testGroup'); \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup'); \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup'); \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup'); $connection = \OC::$server->getDatabaseConnection(); // Share item with group $fileinfo = $this->view->getFileInfo($this->folder); $this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", \OCP\Constants::PERMISSION_READ)); // Login as user 2 and verify the item exists self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder)); $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']); $this->assertNotEmpty($result); $this->assertEquals(\OCP\Constants::PERMISSION_READ, $result['permissions']); // Delete the share $this->assertTrue(\OC\Files\Filesystem::rmdir($this->folder)); $this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder)); // Verify we do not get a share $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']); $this->assertEmpty($result); // Verify that the permission is correct in the DB $qb = $connection->getQueryBuilder(); $qb->select('*')->from('share')->where($qb->expr()->eq('file_source', $qb->createParameter('fileSource')))->andWhere($qb->expr()->eq('share_type', $qb->createParameter('shareType')))->setParameter(':fileSource', $fileinfo['fileid'])->setParameter(':shareType', 2); $res = $qb->execute()->fetchAll(); $this->assertCount(1, $res); $this->assertEquals(0, $res[0]['permissions']); // Login as user 1 again and change permissions self::loginHelper(self::TEST_FILES_SHARING_API_USER1); $this->assertTrue(\OCP\Share::setPermissions('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", \OCP\Constants::PERMISSION_ALL)); // Login as user 2 and verify self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder)); $result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']); $this->assertEmpty($result); $connection = \OC::$server->getDatabaseConnection(); $qb = $connection->getQueryBuilder(); $qb->select('*')->from('share')->where($qb->expr()->eq('file_source', $qb->createParameter('fileSource')))->andWhere($qb->expr()->eq('share_type', $qb->createParameter('shareType')))->setParameter(':fileSource', $fileinfo['fileid'])->setParameter(':shareType', 2); $res = $qb->execute()->fetchAll(); $this->assertCount(1, $res); $this->assertEquals(0, $res[0]['permissions']); //cleanup self::loginHelper(self::TEST_FILES_SHARING_API_USER1); \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup'); \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup'); \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup'); \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup'); }
/** * Deletes all files in this directory, and then itself * * @return void * @throws Sabre_DAV_Exception_Forbidden */ public function delete() { if (!\OC\Files\Filesystem::isDeletable($this->path)) { throw new \Sabre_DAV_Exception_Forbidden(); } if ($this->path != "/Shared") { foreach ($this->getChildren() as $child) { $child->delete(); } \OC\Files\Filesystem::rmdir($this->path); } }