/** * @dataProvider maskProvider * @param int $mask */ public function testGetMasked($mask) { $cache = $this->getMaskedCached($mask); $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain', 'permissions' => Constants::PERMISSION_ALL); $this->sourceCache->put('foo', $data); $result = $cache->get('foo'); $this->assertEquals($mask, $result['permissions']); $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain', 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE); $this->sourceCache->put('bar', $data); $result = $cache->get('bar'); $this->assertEquals($mask & ~Constants::PERMISSION_DELETE, $result['permissions']); }
function tearDown() { $this->sharedCache->clear(); self::loginHelper(self::TEST_FILES_SHARING_API_USER1); $fileinfo = $this->view->getFileInfo('container/shareddir'); \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2); $fileinfo = $this->view->getFileInfo('container/shared single file.txt'); \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2); $this->view->deleteAll('container'); $this->ownerCache->clear(); parent::tearDown(); }
public function testTouchWithMountPoints() { $storage2 = new \OC\Files\Storage\Temporary(array()); $cache2 = $storage2->getCache(); Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage'); Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd'); $this->assertTrue($cache2->inCache('foo.txt')); $folderCachedData = $this->cache->get('folder'); $substorageCachedData = $cache2->get(''); $fooCachedData = $cache2->get('foo.txt'); $cachedData = $cache2->get('foo.txt'); $time = 1371006070; $this->cache->put('folder', ['mtime' => $time - 100]); Filesystem::touch('folder/substorage/foo.txt', $time); $cachedData = $cache2->get('foo.txt'); $this->assertInternalType('string', $fooCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($fooCachedData['etag'], $cachedData['etag']); $this->assertEquals($time, $cachedData['mtime']); $cachedData = $cache2->get(''); $this->assertInternalType('string', $substorageCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']); $cachedData = $this->cache->get('folder'); $this->assertInternalType('string', $folderCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']); $this->assertEquals($time, $cachedData['mtime']); }
protected function tearDown() { if ($this->cache) { $this->cache->clear(); } parent::tearDown(); }
private static function checkUpdate($id) { $cacheItem = Cache::getById($id); if (is_null($cacheItem)) { return; } list($storageId, $internalPath) = $cacheItem; $mounts = Filesystem::getMountByStorageId($storageId); if (count($mounts) === 0) { //if the storage we need isn't mounted on default, try to find a user that has access to the storage $permissionsCache = new Permissions($storageId); $users = $permissionsCache->getUsers($id); if (count($users) === 0) { return; } Filesystem::initMountPoints($users[0]); $mounts = Filesystem::getMountByStorageId($storageId); if (count($mounts) === 0) { return; } } $storage = $mounts[0]->getStorage(); $watcher = new Watcher($storage); $watcher->checkUpdate($internalPath); }
public function testTouch() { $rootCachedData = $this->cache->get(''); $fooCachedData = $this->cache->get('foo.txt'); Filesystem::touch('foo.txt'); $cachedData = $this->cache->get('foo.txt'); $this->assertInternalType('string', $fooCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertGreaterThanOrEqual($fooCachedData['mtime'], $cachedData['mtime']); $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']); $rootCachedData = $cachedData; $time = 1371006070; $barCachedData = $this->cache->get('folder/bar.txt'); $folderCachedData = $this->cache->get('folder'); $this->cache->put('', ['mtime' => $time - 100]); Filesystem::touch('folder/bar.txt', $time); $cachedData = $this->cache->get('folder/bar.txt'); $this->assertInternalType('string', $barCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($barCachedData['etag'], $cachedData['etag']); $this->assertEquals($time, $cachedData['mtime']); $cachedData = $this->cache->get('folder'); $this->assertInternalType('string', $folderCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']); $cachedData = $this->cache->get(''); $this->assertInternalType('string', $rootCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($rootCachedData['etag'], $cachedData['etag']); $this->assertEquals($time, $cachedData['mtime']); }
public function getFolderContentsById($id) { $results = parent::getFolderContentsById($id); foreach ($results as &$file) { $file['displayname_owner'] = $this->remoteUser . '@' . $this->remote; } return $results; }
/** * update the storage_mtime of the direct parent in the cache to the mtime from the storage * * @param string $internalPath */ private function correctParentStorageMtime($internalPath) { $parentId = $this->cache->getParentId($internalPath); $parent = dirname($internalPath); if ($parentId != -1) { $this->cache->update($parentId, array('storage_mtime' => $this->storage->filemtime($parent))); } }
public function getFolderContents($path) { $content = parent::getFolderContents($path); foreach ($content as &$data) { $data['permissions'] &= \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE; } return $content; }
/** * remove deleted files in $path from the cache * * @param string $path */ public function cleanFolder($path) { $cachedContent = $this->cache->getFolderContents($path); foreach ($cachedContent as $entry) { if (!$this->storage->file_exists($entry['path'])) { $this->cache->remove($entry['path']); } } }
/** * walk over any folders that are not fully scanned yet and scan them */ public function backgroundScan() { $lastPath = null; while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { $this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG); $this->cache->correctFolderSize($path); $lastPath = $path; } }
/** * walk over any folders that are not fully scanned yet and scan them */ public function backgroundScan() { $lastPath = null; while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { $this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG); \OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path)); if ($this->cacheActive) { $this->cache->correctFolderSize($path); } $lastPath = $path; } }
public function testMoveFolderCrossStorage() { $storage2 = new Temporary(array()); $cache2 = $storage2->getCache(); Filesystem::mount($storage2, array(), '/bar'); $this->storage->mkdir('foo'); $this->storage->mkdir('foo/bar'); $this->storage->file_put_contents('foo/foo.txt', 'qwerty'); $this->storage->file_put_contents('foo/bar.txt', 'foo'); $this->storage->file_put_contents('foo/bar/bar.txt', 'qwertyuiop'); $this->storage->getScanner()->scan(''); $this->assertTrue($this->cache->inCache('foo')); $this->assertTrue($this->cache->inCache('foo/foo.txt')); $this->assertTrue($this->cache->inCache('foo/bar.txt')); $this->assertTrue($this->cache->inCache('foo/bar')); $this->assertTrue($this->cache->inCache('foo/bar/bar.txt')); $cached = []; $cached[] = $this->cache->get('foo'); $cached[] = $this->cache->get('foo/foo.txt'); $cached[] = $this->cache->get('foo/bar.txt'); $cached[] = $this->cache->get('foo/bar'); $cached[] = $this->cache->get('foo/bar/bar.txt'); // add extension to trigger the possible mimetype change $this->view->rename('/foo', '/bar/foo.b'); $this->assertFalse($this->cache->inCache('foo')); $this->assertFalse($this->cache->inCache('foo/foo.txt')); $this->assertFalse($this->cache->inCache('foo/bar.txt')); $this->assertFalse($this->cache->inCache('foo/bar')); $this->assertFalse($this->cache->inCache('foo/bar/bar.txt')); $this->assertTrue($cache2->inCache('foo.b')); $this->assertTrue($cache2->inCache('foo.b/foo.txt')); $this->assertTrue($cache2->inCache('foo.b/bar.txt')); $this->assertTrue($cache2->inCache('foo.b/bar')); $this->assertTrue($cache2->inCache('foo.b/bar/bar.txt')); $cachedTarget = []; $cachedTarget[] = $cache2->get('foo.b'); $cachedTarget[] = $cache2->get('foo.b/foo.txt'); $cachedTarget[] = $cache2->get('foo.b/bar.txt'); $cachedTarget[] = $cache2->get('foo.b/bar'); $cachedTarget[] = $cache2->get('foo.b/bar/bar.txt'); foreach ($cached as $i => $old) { $new = $cachedTarget[$i]; $this->assertEquals($old['mtime'], $new['mtime']); $this->assertEquals($old['size'], $new['size']); $this->assertEquals($old['etag'], $new['etag']); $this->assertEquals($old['fileid'], $new['fileid']); $this->assertEquals($old['mimetype'], $new['mimetype']); } }
/** * @param string $path * @return ICacheEntry */ public function get($path) { $data = parent::get($path); if ($path === '' or $path === '/') { // only the size of the "files" dir counts $filesData = parent::get('files'); if (isset($filesData['size'])) { $data['size'] = $filesData['size']; } } return $data; }
/** * Returns the sizes of the path and its parent dirs in a hash * where the key is the path and the value is the size. * @param string $path */ function getOwnerDirSizes($path) { $result = array(); while ($path != '' && $path != '' && $path != '.') { $cachedData = $this->ownerCache->get($path); $result[$path] = $cachedData['size']; $path = dirname($path); } $cachedData = $this->ownerCache->get(''); $result[''] = $cachedData['size']; return $result; }
protected function tearDown() { if ($this->sharedCache) { $this->sharedCache->clear(); } self::loginHelper(self::TEST_FILES_SHARING_API_USER1); $shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER); foreach ($shares as $share) { $this->shareManager->deleteShare($share); } $this->view->deleteAll('container'); $this->ownerCache->clear(); parent::tearDown(); }
public function testMoveDisabled() { $this->storage->file_put_contents('foo.txt', 'qwerty'); $this->updater->update('foo.txt'); $this->assertTrue($this->cache->inCache('foo.txt')); $this->assertFalse($this->cache->inCache('bar.txt')); $cached = $this->cache->get('foo.txt'); $this->storage->rename('foo.txt', 'bar.txt'); $this->assertTrue($this->cache->inCache('foo.txt')); $this->assertFalse($this->cache->inCache('bar.txt')); $this->updater->disable(); $this->updater->rename('foo.txt', 'bar.txt'); $this->assertTrue($this->cache->inCache('foo.txt')); $this->assertFalse($this->cache->inCache('bar.txt')); }
/** * Test searching by tag for multiple sections of the tree */ function testSearchByTagTree() { $userId = \OC::$server->getUserSession()->getUser()->getUId(); $this->sharedStorage->mkdir('subdir/emptydir'); $this->sharedStorage->mkdir('subdir/emptydir2'); $this->ownerStorage->getScanner()->scan(''); $allIds = array($this->sharedCache->get('')['fileid'], $this->sharedCache->get('bar.txt')['fileid'], $this->sharedCache->get('subdir/another too.txt')['fileid'], $this->sharedCache->get('subdir/not a text file.xml')['fileid'], $this->sharedCache->get('subdir/another.txt')['fileid'], $this->sharedCache->get('subdir/emptydir')['fileid'], $this->sharedCache->get('subdir/emptydir2')['fileid']); $tagManager = \OC::$server->getTagManager()->load('files', null, null, $userId); foreach ($allIds as $id) { $tagManager->tagAs($id, 'tag1'); } $results = $this->sharedStorage->getCache()->searchByTag('tag1', $userId); $check = array(array('name' => 'shareddir', 'path' => ''), array('name' => 'bar.txt', 'path' => 'bar.txt'), array('name' => 'another.txt', 'path' => 'subdir/another.txt'), array('name' => 'another too.txt', 'path' => 'subdir/another too.txt'), array('name' => 'emptydir', 'path' => 'subdir/emptydir'), array('name' => 'emptydir2', 'path' => 'subdir/emptydir2'), array('name' => 'not a text file.xml', 'path' => 'subdir/not a text file.xml')); $this->verifyFiles($check, $results); $tagManager->delete(array('tag1')); }
public function testUpdateLegacyAndNewId() { // add storage ids $oldCache = new \OC\Files\Cache\Cache($this->oldId); new \OC\Files\Cache\Cache($this->newId); // add file to old cache $fileId = $oldCache->put('/', array('size' => 0, 'mtime' => time(), 'mimetype' => 'httpd/directory')); try { $this->instance = new \OC\Files\Storage\AmazonS3($this->params); } catch (\Exception $e) { //ignore } $storages = $this->getStorages(); $this->assertTrue(isset($storages[$this->newId])); $this->assertFalse(isset($storages[$this->oldId])); $this->assertNull(\OC\Files\Cache\Cache::getById($fileId), 'old filecache has not been cleared'); }
private function runBackgroundScanJob(callable $callback, $path) { try { $callback(); \OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path)); if ($this->cacheActive && $this->cache instanceof Cache) { $this->cache->correctFolderSize($path); } } catch (\OCP\Files\StorageInvalidException $e) { // skip unavailable storages } catch (\OCP\Files\StorageNotAvailableException $e) { // skip unavailable storages } catch (\OCP\Files\ForbiddenException $e) { // skip forbidden storages } catch (\OCP\Lock\LockedException $e) { // skip unavailable storages } }
public function testRepairParentShallow() { $this->fillTestFolders(); $this->scanner->scan(''); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $oldFolderId = $this->cache->getId('folder'); // delete the folder without removing the childs $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?'; \OC_DB::executeAudited($sql, array($oldFolderId)); $cachedData = $this->cache->get('folder/bar.txt'); $this->assertEquals($oldFolderId, $cachedData['parent']); $this->assertFalse($this->cache->inCache('folder')); $this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW); $this->assertTrue($this->cache->inCache('folder')); $newFolderId = $this->cache->getId('folder'); $this->assertNotEquals($oldFolderId, $newFolderId); $cachedData = $this->cache->get('folder/bar.txt'); $this->assertEquals($newFolderId, $cachedData['parent']); }
public function testMove() { $this->storage->file_put_contents('foo.txt', 'qwerty'); $this->updater->update('foo.txt'); $this->assertTrue($this->cache->inCache('foo.txt')); $this->assertFalse($this->cache->inCache('bar.txt')); $cached = $this->cache->get('foo.txt'); $this->storage->rename('foo.txt', 'bar.txt'); $this->assertTrue($this->cache->inCache('foo.txt')); $this->assertFalse($this->cache->inCache('bar.txt')); $this->updater->rename('foo.txt', 'bar.txt'); $this->assertFalse($this->cache->inCache('foo.txt')); $this->assertTrue($this->cache->inCache('bar.txt')); $cachedTarget = $this->cache->get('bar.txt'); $this->assertEquals($cached['etag'], $cachedTarget['etag']); $this->assertEquals($cached['mtime'], $cachedTarget['mtime']); $this->assertEquals($cached['size'], $cachedTarget['size']); $this->assertEquals($cached['fileid'], $cachedTarget['fileid']); }
function testClearKeepEntriesOutsideJail() { $file1 = 'foo/foobar'; $file2 = 'foo/foobar/asd'; $file3 = 'folder/foobar'; $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'); $this->sourceCache->put('foo', $data1); $this->sourceCache->put($file1, $data1); $this->sourceCache->put($file2, $data1); $this->sourceCache->put($file3, $data1); $this->cache->clear(); $this->assertFalse($this->cache->inCache('foobar')); $this->assertTrue($this->sourceCache->inCache('folder/foobar')); }
/** * walk over any folders that are not fully scanned yet and scan them */ public function backgroundScan() { $lastPath = null; while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { try { $this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG); \OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path)); if ($this->cacheActive) { $this->cache->correctFolderSize($path); } } catch (\OCP\Files\StorageInvalidException $e) { // skip unavailable storages } catch (\OCP\Files\StorageNotAvailableException $e) { // skip unavailable storages } catch (\OCP\Lock\LockedException $e) { // skip unavailable storages } // FIXME: this won't proceed with the next item, needs revamping of getIncomplete() // to make this possible $lastPath = $path; } }
/** * check if a file is available in the cache * * @param string $file * @return bool */ public function inCache($file) { if ($file == '') { return true; } return parent::inCache($file); }
/** * Move a file or folder in the cache * * @param \OC\Files\Cache\Cache $sourceCache * @param string $sourcePath * @param string $targetPath * @throws \OC\DatabaseException */ public function moveFromCache(Cache $sourceCache, $sourcePath, $targetPath) { // normalize source and target $sourcePath = $this->normalize($sourcePath); $targetPath = $this->normalize($targetPath); $sourceData = $sourceCache->get($sourcePath); $sourceId = $sourceData['fileid']; $newParentId = $this->getParentId($targetPath); list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath); list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath); // sql for final update $moveSql = 'UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?'; if ($sourceData['mimetype'] === 'httpd/unix-directory') { //find all child entries $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?'; $result = $this->connection->executeQuery($sql, [$sourceStorageId, $this->connection->escapeLikeParameter($sourcePath) . '/%']); $childEntries = $result->fetchAll(); $sourceLength = strlen($sourcePath); $this->connection->beginTransaction(); $query = $this->connection->prepare('UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ? WHERE `fileid` = ?'); foreach ($childEntries as $child) { $newTargetPath = $targetPath . substr($child['path'], $sourceLength); $query->execute([$targetStorageId, $newTargetPath, md5($newTargetPath), $child['fileid']]); } $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); $this->connection->commit(); } else { $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); } }
public function tearDown() { if ($this->cache) { $this->cache->clear(); } }
/** * get the storage id of the storage for a file and the internal path of the file * unlike getPathById this does not limit the search to files on this storage and * instead does a global search in the cache table * * @param int $id * @return array, first element holding the storage id, second the path */ public static function getById($id) { return parent::getById($id); }
protected function getLocalFileOwnerAndPath() { $fileInfo = \OC\Files\Cache\Cache::getById($this->fileId); $owner = \OCP\User::getUser(); if (!$owner) { throw new Exception('Guest users can\'t access local files. This one was probably unshared recently.'); } return array($owner, @$fileInfo[1]); }
/** * Create dummy data in the filecache for the given storage numeric id * * @param string $storageId storage id */ private function createData($storageId) { $cache = new Cache($storageId); $cache->put('dummyfile.txt', array('size' => 5, 'mtime' => 12, 'mimetype' => 'text/plain')); }