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 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'); }
function testLongId() { $storage = new LongId(array()); $cache = $storage->getCache(); $storageId = $storage->getId(); $data = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file'); $id = $cache->put('foo', $data); $this->assertEquals(array(md5($storageId), 'foo'), \OC\Files\Cache\Cache::getById($id)); }
/** * 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]); }
/** * Get the path including the storage mount point * @param int $id * @return string the path including the mount point like AmazonS3/folder/file.txt */ public function getPathWithMountPoint($id) { list($storage, $internalPath) = \OC\Files\Cache\Cache::getById($id); $mount = \OC\Files\Filesystem::getMountByStorageId($storage); $mountPoint = $mount[0]->getMountPoint(); $path = \OC\Files\Filesystem::normalizePath($mountPoint . '/' . $internalPath); // reformat the path to be relative e.g. /user/files/folder becomes /folder/ $relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path); return $relativePath; }
/** * search file by id * * An array is returned because in the case where a single storage is mounted in different places the same file * can exist in different places * * @param int $id * @throws \OCP\Files\NotFoundException * @return Node[] */ public function getById($id) { $result = Cache::getById($id); if (is_null($result)) { throw new NotFoundException(); } else { list($storageId, $internalPath) = $result; $nodes = array(); $mounts = $this->mountManager->findByStorageId($storageId); foreach ($mounts as $mount) { $nodes[] = $this->get($mount->getMountPoint() . $internalPath); } return $nodes; } }
public function isValidSource($itemSource, $uidOwner) { return is_array(\OC\Files\Cache\Cache::getById($itemSource)); }