@@ -36,399 +36,399 @@ |
||
| 36 | 36 | use OCP\Files\Search\ISearchOperator; |
| 37 | 37 | |
| 38 | 38 | class Folder extends Node implements \OCP\Files\Folder { |
| 39 | - /** |
|
| 40 | - * Creates a Folder that represents a non-existing path |
|
| 41 | - * |
|
| 42 | - * @param string $path path |
|
| 43 | - * @return string non-existing node class |
|
| 44 | - */ |
|
| 45 | - protected function createNonExistingNode($path) { |
|
| 46 | - return new NonExistingFolder($this->root, $this->view, $path); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param string $path path relative to the folder |
|
| 51 | - * @return string |
|
| 52 | - * @throws \OCP\Files\NotPermittedException |
|
| 53 | - */ |
|
| 54 | - public function getFullPath($path) { |
|
| 55 | - if (!$this->isValidPath($path)) { |
|
| 56 | - throw new NotPermittedException('Invalid path'); |
|
| 57 | - } |
|
| 58 | - return $this->path . $this->normalizePath($path); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param string $path |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - public function getRelativePath($path) { |
|
| 66 | - if ($this->path === '' or $this->path === '/') { |
|
| 67 | - return $this->normalizePath($path); |
|
| 68 | - } |
|
| 69 | - if ($path === $this->path) { |
|
| 70 | - return '/'; |
|
| 71 | - } else if (strpos($path, $this->path . '/') !== 0) { |
|
| 72 | - return null; |
|
| 73 | - } else { |
|
| 74 | - $path = substr($path, strlen($this->path)); |
|
| 75 | - return $this->normalizePath($path); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * check if a node is a (grand-)child of the folder |
|
| 81 | - * |
|
| 82 | - * @param \OC\Files\Node\Node $node |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - public function isSubNode($node) { |
|
| 86 | - return strpos($node->getPath(), $this->path . '/') === 0; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * get the content of this directory |
|
| 91 | - * |
|
| 92 | - * @throws \OCP\Files\NotFoundException |
|
| 93 | - * @return Node[] |
|
| 94 | - */ |
|
| 95 | - public function getDirectoryListing() { |
|
| 96 | - $folderContent = $this->view->getDirectoryContent($this->path); |
|
| 97 | - |
|
| 98 | - return array_map(function (FileInfo $info) { |
|
| 99 | - if ($info->getMimetype() === 'httpd/unix-directory') { |
|
| 100 | - return new Folder($this->root, $this->view, $info->getPath(), $info); |
|
| 101 | - } else { |
|
| 102 | - return new File($this->root, $this->view, $info->getPath(), $info); |
|
| 103 | - } |
|
| 104 | - }, $folderContent); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param string $path |
|
| 109 | - * @param FileInfo $info |
|
| 110 | - * @return File|Folder |
|
| 111 | - */ |
|
| 112 | - protected function createNode($path, FileInfo $info = null) { |
|
| 113 | - if (is_null($info)) { |
|
| 114 | - $isDir = $this->view->is_dir($path); |
|
| 115 | - } else { |
|
| 116 | - $isDir = $info->getType() === FileInfo::TYPE_FOLDER; |
|
| 117 | - } |
|
| 118 | - if ($isDir) { |
|
| 119 | - return new Folder($this->root, $this->view, $path, $info); |
|
| 120 | - } else { |
|
| 121 | - return new File($this->root, $this->view, $path, $info); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Get the node at $path |
|
| 127 | - * |
|
| 128 | - * @param string $path |
|
| 129 | - * @return \OC\Files\Node\Node |
|
| 130 | - * @throws \OCP\Files\NotFoundException |
|
| 131 | - */ |
|
| 132 | - public function get($path) { |
|
| 133 | - return $this->root->get($this->getFullPath($path)); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param string $path |
|
| 138 | - * @return bool |
|
| 139 | - */ |
|
| 140 | - public function nodeExists($path) { |
|
| 141 | - try { |
|
| 142 | - $this->get($path); |
|
| 143 | - return true; |
|
| 144 | - } catch (NotFoundException $e) { |
|
| 145 | - return false; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param string $path |
|
| 151 | - * @return \OC\Files\Node\Folder |
|
| 152 | - * @throws \OCP\Files\NotPermittedException |
|
| 153 | - */ |
|
| 154 | - public function newFolder($path) { |
|
| 155 | - if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 156 | - $fullPath = $this->getFullPath($path); |
|
| 157 | - $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); |
|
| 158 | - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 159 | - $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 160 | - $this->view->mkdir($fullPath); |
|
| 161 | - $node = new Folder($this->root, $this->view, $fullPath); |
|
| 162 | - $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 163 | - $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 164 | - return $node; |
|
| 165 | - } else { |
|
| 166 | - throw new NotPermittedException('No create permission for folder'); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param string $path |
|
| 172 | - * @return \OC\Files\Node\File |
|
| 173 | - * @throws \OCP\Files\NotPermittedException |
|
| 174 | - */ |
|
| 175 | - public function newFile($path) { |
|
| 176 | - if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 177 | - $fullPath = $this->getFullPath($path); |
|
| 178 | - $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); |
|
| 179 | - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 180 | - $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 181 | - $this->view->touch($fullPath); |
|
| 182 | - $node = new File($this->root, $this->view, $fullPath); |
|
| 183 | - $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 184 | - $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 185 | - return $node; |
|
| 186 | - } else { |
|
| 187 | - throw new NotPermittedException('No create permission for path'); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * search for files with the name matching $query |
|
| 193 | - * |
|
| 194 | - * @param string|ISearchOperator $query |
|
| 195 | - * @return \OC\Files\Node\Node[] |
|
| 196 | - */ |
|
| 197 | - public function search($query) { |
|
| 198 | - if (is_string($query)) { |
|
| 199 | - return $this->searchCommon('search', array('%' . $query . '%')); |
|
| 200 | - } else { |
|
| 201 | - return $this->searchCommon('searchQuery', array($query)); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * search for files by mimetype |
|
| 207 | - * |
|
| 208 | - * @param string $mimetype |
|
| 209 | - * @return Node[] |
|
| 210 | - */ |
|
| 211 | - public function searchByMime($mimetype) { |
|
| 212 | - return $this->searchCommon('searchByMime', array($mimetype)); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * search for files by tag |
|
| 217 | - * |
|
| 218 | - * @param string|int $tag name or tag id |
|
| 219 | - * @param string $userId owner of the tags |
|
| 220 | - * @return Node[] |
|
| 221 | - */ |
|
| 222 | - public function searchByTag($tag, $userId) { |
|
| 223 | - return $this->searchCommon('searchByTag', array($tag, $userId)); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @param string $method cache method |
|
| 228 | - * @param array $args call args |
|
| 229 | - * @return \OC\Files\Node\Node[] |
|
| 230 | - */ |
|
| 231 | - private function searchCommon($method, $args) { |
|
| 232 | - $files = array(); |
|
| 233 | - $rootLength = strlen($this->path); |
|
| 234 | - $mount = $this->root->getMount($this->path); |
|
| 235 | - $storage = $mount->getStorage(); |
|
| 236 | - $internalPath = $mount->getInternalPath($this->path); |
|
| 237 | - $internalPath = rtrim($internalPath, '/'); |
|
| 238 | - if ($internalPath !== '') { |
|
| 239 | - $internalPath = $internalPath . '/'; |
|
| 240 | - } |
|
| 241 | - $internalRootLength = strlen($internalPath); |
|
| 242 | - |
|
| 243 | - $cache = $storage->getCache(''); |
|
| 244 | - |
|
| 245 | - $results = call_user_func_array(array($cache, $method), $args); |
|
| 246 | - foreach ($results as $result) { |
|
| 247 | - if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) { |
|
| 248 | - $result['internalPath'] = $result['path']; |
|
| 249 | - $result['path'] = substr($result['path'], $internalRootLength); |
|
| 250 | - $result['storage'] = $storage; |
|
| 251 | - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $mounts = $this->root->getMountsIn($this->path); |
|
| 256 | - foreach ($mounts as $mount) { |
|
| 257 | - $storage = $mount->getStorage(); |
|
| 258 | - if ($storage) { |
|
| 259 | - $cache = $storage->getCache(''); |
|
| 260 | - |
|
| 261 | - $relativeMountPoint = substr($mount->getMountPoint(), $rootLength); |
|
| 262 | - $results = call_user_func_array(array($cache, $method), $args); |
|
| 263 | - foreach ($results as $result) { |
|
| 264 | - $result['internalPath'] = $result['path']; |
|
| 265 | - $result['path'] = $relativeMountPoint . $result['path']; |
|
| 266 | - $result['storage'] = $storage; |
|
| 267 | - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return array_map(function (FileInfo $file) { |
|
| 273 | - return $this->createNode($file->getPath(), $file); |
|
| 274 | - }, $files); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @param int $id |
|
| 279 | - * @return \OC\Files\Node\Node[] |
|
| 280 | - */ |
|
| 281 | - public function getById($id) { |
|
| 282 | - $mountCache = $this->root->getUserMountCache(); |
|
| 283 | - if (strpos($this->getPath(), '/', 1) > 0) { |
|
| 284 | - list(, $user) = explode('/', $this->getPath()); |
|
| 285 | - } else { |
|
| 286 | - $user = null; |
|
| 287 | - } |
|
| 288 | - $mountsContainingFile = $mountCache->getMountsForFileId((int)$id, $user); |
|
| 289 | - $mounts = $this->root->getMountsIn($this->path); |
|
| 290 | - $mounts[] = $this->root->getMount($this->path); |
|
| 291 | - /** @var IMountPoint[] $folderMounts */ |
|
| 292 | - $folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) { |
|
| 293 | - return $mountPoint->getMountPoint(); |
|
| 294 | - }, $mounts), $mounts); |
|
| 295 | - |
|
| 296 | - /** @var ICachedMountInfo[] $mountsContainingFile */ |
|
| 297 | - $mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) { |
|
| 298 | - return isset($folderMounts[$cachedMountInfo->getMountPoint()]); |
|
| 299 | - })); |
|
| 300 | - |
|
| 301 | - if (count($mountsContainingFile) === 0) { |
|
| 302 | - return []; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - // we only need to get the cache info once, since all mounts we found point to the same storage |
|
| 306 | - |
|
| 307 | - $mount = $folderMounts[$mountsContainingFile[0]->getMountPoint()]; |
|
| 308 | - $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); |
|
| 309 | - if (!$cacheEntry) { |
|
| 310 | - return []; |
|
| 311 | - } |
|
| 312 | - // cache jails will hide the "true" internal path |
|
| 313 | - $internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); |
|
| 314 | - |
|
| 315 | - $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) { |
|
| 316 | - $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; |
|
| 317 | - $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); |
|
| 318 | - $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); |
|
| 319 | - $absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount; |
|
| 320 | - return $this->root->createNode($absolutePath, new \OC\Files\FileInfo( |
|
| 321 | - $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount, |
|
| 322 | - \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount)) |
|
| 323 | - )); |
|
| 324 | - }, $mountsContainingFile); |
|
| 325 | - |
|
| 326 | - return array_filter($nodes, function (Node $node) { |
|
| 327 | - return $this->getRelativePath($node->getPath()); |
|
| 328 | - }); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - public function getFreeSpace() { |
|
| 332 | - return $this->view->free_space($this->path); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - public function delete() { |
|
| 336 | - if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { |
|
| 337 | - $this->sendHooks(array('preDelete')); |
|
| 338 | - $fileInfo = $this->getFileInfo(); |
|
| 339 | - $this->view->rmdir($this->path); |
|
| 340 | - $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo); |
|
| 341 | - $this->root->emit('\OC\Files', 'postDelete', array($nonExisting)); |
|
| 342 | - $this->exists = false; |
|
| 343 | - } else { |
|
| 344 | - throw new NotPermittedException('No delete permission for path'); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Add a suffix to the name in case the file exists |
|
| 350 | - * |
|
| 351 | - * @param string $name |
|
| 352 | - * @return string |
|
| 353 | - * @throws NotPermittedException |
|
| 354 | - */ |
|
| 355 | - public function getNonExistingName($name) { |
|
| 356 | - $uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view); |
|
| 357 | - return trim($this->getRelativePath($uniqueName), '/'); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @param int $limit |
|
| 362 | - * @param int $offset |
|
| 363 | - * @return \OCP\Files\Node[] |
|
| 364 | - */ |
|
| 365 | - public function getRecent($limit, $offset = 0) { |
|
| 366 | - $mimetypeLoader = \OC::$server->getMimeTypeLoader(); |
|
| 367 | - $mounts = $this->root->getMountsIn($this->path); |
|
| 368 | - $mounts[] = $this->getMountPoint(); |
|
| 369 | - |
|
| 370 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 371 | - return $mount->getStorage(); |
|
| 372 | - }); |
|
| 373 | - $storageIds = array_map(function (IMountPoint $mount) { |
|
| 374 | - return $mount->getStorage()->getCache()->getNumericStorageId(); |
|
| 375 | - }, $mounts); |
|
| 376 | - /** @var IMountPoint[] $mountMap */ |
|
| 377 | - $mountMap = array_combine($storageIds, $mounts); |
|
| 378 | - $folderMimetype = $mimetypeLoader->getId(FileInfo::MIMETYPE_FOLDER); |
|
| 379 | - |
|
| 380 | - //todo look into options of filtering path based on storage id (only search in files/ for home storage, filter by share root for shared, etc) |
|
| 381 | - |
|
| 382 | - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 383 | - $query = $builder |
|
| 384 | - ->select('f.*') |
|
| 385 | - ->from('filecache', 'f') |
|
| 386 | - ->andWhere($builder->expr()->in('f.storage', $builder->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 387 | - ->andWhere($builder->expr()->orX( |
|
| 388 | - // handle non empty folders separate |
|
| 389 | - $builder->expr()->neq('f.mimetype', $builder->createNamedParameter($folderMimetype, IQueryBuilder::PARAM_INT)), |
|
| 390 | - $builder->expr()->eq('f.size', new Literal(0)) |
|
| 391 | - )) |
|
| 392 | - ->orderBy('f.mtime', 'DESC') |
|
| 393 | - ->setMaxResults($limit) |
|
| 394 | - ->setFirstResult($offset); |
|
| 395 | - |
|
| 396 | - $result = $query->execute()->fetchAll(); |
|
| 397 | - |
|
| 398 | - $files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { |
|
| 399 | - $mount = $mountMap[$entry['storage']]; |
|
| 400 | - $entry['internalPath'] = $entry['path']; |
|
| 401 | - $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']); |
|
| 402 | - $entry['mimepart'] = $mimetypeLoader->getMimetypeById($entry['mimepart']); |
|
| 403 | - $path = $this->getAbsolutePath($mount, $entry['path']); |
|
| 404 | - if (is_null($path)) { |
|
| 405 | - return null; |
|
| 406 | - } |
|
| 407 | - $fileInfo = new \OC\Files\FileInfo($path, $mount->getStorage(), $entry['internalPath'], $entry, $mount); |
|
| 408 | - return $this->root->createNode($fileInfo->getPath(), $fileInfo); |
|
| 409 | - }, $result)); |
|
| 410 | - |
|
| 411 | - return array_values(array_filter($files, function (Node $node) { |
|
| 412 | - $relative = $this->getRelativePath($node->getPath()); |
|
| 413 | - return $relative !== null && $relative !== '/'; |
|
| 414 | - })); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - private function getAbsolutePath(IMountPoint $mount, $path) { |
|
| 418 | - $storage = $mount->getStorage(); |
|
| 419 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) { |
|
| 420 | - /** @var \OC\Files\Storage\Wrapper\Jail $storage */ |
|
| 421 | - $jailRoot = $storage->getUnjailedPath(''); |
|
| 422 | - $rootLength = strlen($jailRoot) + 1; |
|
| 423 | - if ($path === $jailRoot) { |
|
| 424 | - return $mount->getMountPoint(); |
|
| 425 | - } else if (substr($path, 0, $rootLength) === $jailRoot . '/') { |
|
| 426 | - return $mount->getMountPoint() . substr($path, $rootLength); |
|
| 427 | - } else { |
|
| 428 | - return null; |
|
| 429 | - } |
|
| 430 | - } else { |
|
| 431 | - return $mount->getMountPoint() . $path; |
|
| 432 | - } |
|
| 433 | - } |
|
| 39 | + /** |
|
| 40 | + * Creates a Folder that represents a non-existing path |
|
| 41 | + * |
|
| 42 | + * @param string $path path |
|
| 43 | + * @return string non-existing node class |
|
| 44 | + */ |
|
| 45 | + protected function createNonExistingNode($path) { |
|
| 46 | + return new NonExistingFolder($this->root, $this->view, $path); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param string $path path relative to the folder |
|
| 51 | + * @return string |
|
| 52 | + * @throws \OCP\Files\NotPermittedException |
|
| 53 | + */ |
|
| 54 | + public function getFullPath($path) { |
|
| 55 | + if (!$this->isValidPath($path)) { |
|
| 56 | + throw new NotPermittedException('Invalid path'); |
|
| 57 | + } |
|
| 58 | + return $this->path . $this->normalizePath($path); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param string $path |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + public function getRelativePath($path) { |
|
| 66 | + if ($this->path === '' or $this->path === '/') { |
|
| 67 | + return $this->normalizePath($path); |
|
| 68 | + } |
|
| 69 | + if ($path === $this->path) { |
|
| 70 | + return '/'; |
|
| 71 | + } else if (strpos($path, $this->path . '/') !== 0) { |
|
| 72 | + return null; |
|
| 73 | + } else { |
|
| 74 | + $path = substr($path, strlen($this->path)); |
|
| 75 | + return $this->normalizePath($path); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * check if a node is a (grand-)child of the folder |
|
| 81 | + * |
|
| 82 | + * @param \OC\Files\Node\Node $node |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + public function isSubNode($node) { |
|
| 86 | + return strpos($node->getPath(), $this->path . '/') === 0; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * get the content of this directory |
|
| 91 | + * |
|
| 92 | + * @throws \OCP\Files\NotFoundException |
|
| 93 | + * @return Node[] |
|
| 94 | + */ |
|
| 95 | + public function getDirectoryListing() { |
|
| 96 | + $folderContent = $this->view->getDirectoryContent($this->path); |
|
| 97 | + |
|
| 98 | + return array_map(function (FileInfo $info) { |
|
| 99 | + if ($info->getMimetype() === 'httpd/unix-directory') { |
|
| 100 | + return new Folder($this->root, $this->view, $info->getPath(), $info); |
|
| 101 | + } else { |
|
| 102 | + return new File($this->root, $this->view, $info->getPath(), $info); |
|
| 103 | + } |
|
| 104 | + }, $folderContent); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param string $path |
|
| 109 | + * @param FileInfo $info |
|
| 110 | + * @return File|Folder |
|
| 111 | + */ |
|
| 112 | + protected function createNode($path, FileInfo $info = null) { |
|
| 113 | + if (is_null($info)) { |
|
| 114 | + $isDir = $this->view->is_dir($path); |
|
| 115 | + } else { |
|
| 116 | + $isDir = $info->getType() === FileInfo::TYPE_FOLDER; |
|
| 117 | + } |
|
| 118 | + if ($isDir) { |
|
| 119 | + return new Folder($this->root, $this->view, $path, $info); |
|
| 120 | + } else { |
|
| 121 | + return new File($this->root, $this->view, $path, $info); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Get the node at $path |
|
| 127 | + * |
|
| 128 | + * @param string $path |
|
| 129 | + * @return \OC\Files\Node\Node |
|
| 130 | + * @throws \OCP\Files\NotFoundException |
|
| 131 | + */ |
|
| 132 | + public function get($path) { |
|
| 133 | + return $this->root->get($this->getFullPath($path)); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param string $path |
|
| 138 | + * @return bool |
|
| 139 | + */ |
|
| 140 | + public function nodeExists($path) { |
|
| 141 | + try { |
|
| 142 | + $this->get($path); |
|
| 143 | + return true; |
|
| 144 | + } catch (NotFoundException $e) { |
|
| 145 | + return false; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param string $path |
|
| 151 | + * @return \OC\Files\Node\Folder |
|
| 152 | + * @throws \OCP\Files\NotPermittedException |
|
| 153 | + */ |
|
| 154 | + public function newFolder($path) { |
|
| 155 | + if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 156 | + $fullPath = $this->getFullPath($path); |
|
| 157 | + $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); |
|
| 158 | + $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 159 | + $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 160 | + $this->view->mkdir($fullPath); |
|
| 161 | + $node = new Folder($this->root, $this->view, $fullPath); |
|
| 162 | + $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 163 | + $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 164 | + return $node; |
|
| 165 | + } else { |
|
| 166 | + throw new NotPermittedException('No create permission for folder'); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param string $path |
|
| 172 | + * @return \OC\Files\Node\File |
|
| 173 | + * @throws \OCP\Files\NotPermittedException |
|
| 174 | + */ |
|
| 175 | + public function newFile($path) { |
|
| 176 | + if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 177 | + $fullPath = $this->getFullPath($path); |
|
| 178 | + $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); |
|
| 179 | + $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 180 | + $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 181 | + $this->view->touch($fullPath); |
|
| 182 | + $node = new File($this->root, $this->view, $fullPath); |
|
| 183 | + $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 184 | + $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 185 | + return $node; |
|
| 186 | + } else { |
|
| 187 | + throw new NotPermittedException('No create permission for path'); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * search for files with the name matching $query |
|
| 193 | + * |
|
| 194 | + * @param string|ISearchOperator $query |
|
| 195 | + * @return \OC\Files\Node\Node[] |
|
| 196 | + */ |
|
| 197 | + public function search($query) { |
|
| 198 | + if (is_string($query)) { |
|
| 199 | + return $this->searchCommon('search', array('%' . $query . '%')); |
|
| 200 | + } else { |
|
| 201 | + return $this->searchCommon('searchQuery', array($query)); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * search for files by mimetype |
|
| 207 | + * |
|
| 208 | + * @param string $mimetype |
|
| 209 | + * @return Node[] |
|
| 210 | + */ |
|
| 211 | + public function searchByMime($mimetype) { |
|
| 212 | + return $this->searchCommon('searchByMime', array($mimetype)); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * search for files by tag |
|
| 217 | + * |
|
| 218 | + * @param string|int $tag name or tag id |
|
| 219 | + * @param string $userId owner of the tags |
|
| 220 | + * @return Node[] |
|
| 221 | + */ |
|
| 222 | + public function searchByTag($tag, $userId) { |
|
| 223 | + return $this->searchCommon('searchByTag', array($tag, $userId)); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @param string $method cache method |
|
| 228 | + * @param array $args call args |
|
| 229 | + * @return \OC\Files\Node\Node[] |
|
| 230 | + */ |
|
| 231 | + private function searchCommon($method, $args) { |
|
| 232 | + $files = array(); |
|
| 233 | + $rootLength = strlen($this->path); |
|
| 234 | + $mount = $this->root->getMount($this->path); |
|
| 235 | + $storage = $mount->getStorage(); |
|
| 236 | + $internalPath = $mount->getInternalPath($this->path); |
|
| 237 | + $internalPath = rtrim($internalPath, '/'); |
|
| 238 | + if ($internalPath !== '') { |
|
| 239 | + $internalPath = $internalPath . '/'; |
|
| 240 | + } |
|
| 241 | + $internalRootLength = strlen($internalPath); |
|
| 242 | + |
|
| 243 | + $cache = $storage->getCache(''); |
|
| 244 | + |
|
| 245 | + $results = call_user_func_array(array($cache, $method), $args); |
|
| 246 | + foreach ($results as $result) { |
|
| 247 | + if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) { |
|
| 248 | + $result['internalPath'] = $result['path']; |
|
| 249 | + $result['path'] = substr($result['path'], $internalRootLength); |
|
| 250 | + $result['storage'] = $storage; |
|
| 251 | + $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $mounts = $this->root->getMountsIn($this->path); |
|
| 256 | + foreach ($mounts as $mount) { |
|
| 257 | + $storage = $mount->getStorage(); |
|
| 258 | + if ($storage) { |
|
| 259 | + $cache = $storage->getCache(''); |
|
| 260 | + |
|
| 261 | + $relativeMountPoint = substr($mount->getMountPoint(), $rootLength); |
|
| 262 | + $results = call_user_func_array(array($cache, $method), $args); |
|
| 263 | + foreach ($results as $result) { |
|
| 264 | + $result['internalPath'] = $result['path']; |
|
| 265 | + $result['path'] = $relativeMountPoint . $result['path']; |
|
| 266 | + $result['storage'] = $storage; |
|
| 267 | + $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return array_map(function (FileInfo $file) { |
|
| 273 | + return $this->createNode($file->getPath(), $file); |
|
| 274 | + }, $files); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @param int $id |
|
| 279 | + * @return \OC\Files\Node\Node[] |
|
| 280 | + */ |
|
| 281 | + public function getById($id) { |
|
| 282 | + $mountCache = $this->root->getUserMountCache(); |
|
| 283 | + if (strpos($this->getPath(), '/', 1) > 0) { |
|
| 284 | + list(, $user) = explode('/', $this->getPath()); |
|
| 285 | + } else { |
|
| 286 | + $user = null; |
|
| 287 | + } |
|
| 288 | + $mountsContainingFile = $mountCache->getMountsForFileId((int)$id, $user); |
|
| 289 | + $mounts = $this->root->getMountsIn($this->path); |
|
| 290 | + $mounts[] = $this->root->getMount($this->path); |
|
| 291 | + /** @var IMountPoint[] $folderMounts */ |
|
| 292 | + $folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) { |
|
| 293 | + return $mountPoint->getMountPoint(); |
|
| 294 | + }, $mounts), $mounts); |
|
| 295 | + |
|
| 296 | + /** @var ICachedMountInfo[] $mountsContainingFile */ |
|
| 297 | + $mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) { |
|
| 298 | + return isset($folderMounts[$cachedMountInfo->getMountPoint()]); |
|
| 299 | + })); |
|
| 300 | + |
|
| 301 | + if (count($mountsContainingFile) === 0) { |
|
| 302 | + return []; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + // we only need to get the cache info once, since all mounts we found point to the same storage |
|
| 306 | + |
|
| 307 | + $mount = $folderMounts[$mountsContainingFile[0]->getMountPoint()]; |
|
| 308 | + $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); |
|
| 309 | + if (!$cacheEntry) { |
|
| 310 | + return []; |
|
| 311 | + } |
|
| 312 | + // cache jails will hide the "true" internal path |
|
| 313 | + $internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); |
|
| 314 | + |
|
| 315 | + $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) { |
|
| 316 | + $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; |
|
| 317 | + $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); |
|
| 318 | + $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); |
|
| 319 | + $absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount; |
|
| 320 | + return $this->root->createNode($absolutePath, new \OC\Files\FileInfo( |
|
| 321 | + $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount, |
|
| 322 | + \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount)) |
|
| 323 | + )); |
|
| 324 | + }, $mountsContainingFile); |
|
| 325 | + |
|
| 326 | + return array_filter($nodes, function (Node $node) { |
|
| 327 | + return $this->getRelativePath($node->getPath()); |
|
| 328 | + }); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + public function getFreeSpace() { |
|
| 332 | + return $this->view->free_space($this->path); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + public function delete() { |
|
| 336 | + if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { |
|
| 337 | + $this->sendHooks(array('preDelete')); |
|
| 338 | + $fileInfo = $this->getFileInfo(); |
|
| 339 | + $this->view->rmdir($this->path); |
|
| 340 | + $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo); |
|
| 341 | + $this->root->emit('\OC\Files', 'postDelete', array($nonExisting)); |
|
| 342 | + $this->exists = false; |
|
| 343 | + } else { |
|
| 344 | + throw new NotPermittedException('No delete permission for path'); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Add a suffix to the name in case the file exists |
|
| 350 | + * |
|
| 351 | + * @param string $name |
|
| 352 | + * @return string |
|
| 353 | + * @throws NotPermittedException |
|
| 354 | + */ |
|
| 355 | + public function getNonExistingName($name) { |
|
| 356 | + $uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view); |
|
| 357 | + return trim($this->getRelativePath($uniqueName), '/'); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @param int $limit |
|
| 362 | + * @param int $offset |
|
| 363 | + * @return \OCP\Files\Node[] |
|
| 364 | + */ |
|
| 365 | + public function getRecent($limit, $offset = 0) { |
|
| 366 | + $mimetypeLoader = \OC::$server->getMimeTypeLoader(); |
|
| 367 | + $mounts = $this->root->getMountsIn($this->path); |
|
| 368 | + $mounts[] = $this->getMountPoint(); |
|
| 369 | + |
|
| 370 | + $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 371 | + return $mount->getStorage(); |
|
| 372 | + }); |
|
| 373 | + $storageIds = array_map(function (IMountPoint $mount) { |
|
| 374 | + return $mount->getStorage()->getCache()->getNumericStorageId(); |
|
| 375 | + }, $mounts); |
|
| 376 | + /** @var IMountPoint[] $mountMap */ |
|
| 377 | + $mountMap = array_combine($storageIds, $mounts); |
|
| 378 | + $folderMimetype = $mimetypeLoader->getId(FileInfo::MIMETYPE_FOLDER); |
|
| 379 | + |
|
| 380 | + //todo look into options of filtering path based on storage id (only search in files/ for home storage, filter by share root for shared, etc) |
|
| 381 | + |
|
| 382 | + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 383 | + $query = $builder |
|
| 384 | + ->select('f.*') |
|
| 385 | + ->from('filecache', 'f') |
|
| 386 | + ->andWhere($builder->expr()->in('f.storage', $builder->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 387 | + ->andWhere($builder->expr()->orX( |
|
| 388 | + // handle non empty folders separate |
|
| 389 | + $builder->expr()->neq('f.mimetype', $builder->createNamedParameter($folderMimetype, IQueryBuilder::PARAM_INT)), |
|
| 390 | + $builder->expr()->eq('f.size', new Literal(0)) |
|
| 391 | + )) |
|
| 392 | + ->orderBy('f.mtime', 'DESC') |
|
| 393 | + ->setMaxResults($limit) |
|
| 394 | + ->setFirstResult($offset); |
|
| 395 | + |
|
| 396 | + $result = $query->execute()->fetchAll(); |
|
| 397 | + |
|
| 398 | + $files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { |
|
| 399 | + $mount = $mountMap[$entry['storage']]; |
|
| 400 | + $entry['internalPath'] = $entry['path']; |
|
| 401 | + $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']); |
|
| 402 | + $entry['mimepart'] = $mimetypeLoader->getMimetypeById($entry['mimepart']); |
|
| 403 | + $path = $this->getAbsolutePath($mount, $entry['path']); |
|
| 404 | + if (is_null($path)) { |
|
| 405 | + return null; |
|
| 406 | + } |
|
| 407 | + $fileInfo = new \OC\Files\FileInfo($path, $mount->getStorage(), $entry['internalPath'], $entry, $mount); |
|
| 408 | + return $this->root->createNode($fileInfo->getPath(), $fileInfo); |
|
| 409 | + }, $result)); |
|
| 410 | + |
|
| 411 | + return array_values(array_filter($files, function (Node $node) { |
|
| 412 | + $relative = $this->getRelativePath($node->getPath()); |
|
| 413 | + return $relative !== null && $relative !== '/'; |
|
| 414 | + })); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + private function getAbsolutePath(IMountPoint $mount, $path) { |
|
| 418 | + $storage = $mount->getStorage(); |
|
| 419 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) { |
|
| 420 | + /** @var \OC\Files\Storage\Wrapper\Jail $storage */ |
|
| 421 | + $jailRoot = $storage->getUnjailedPath(''); |
|
| 422 | + $rootLength = strlen($jailRoot) + 1; |
|
| 423 | + if ($path === $jailRoot) { |
|
| 424 | + return $mount->getMountPoint(); |
|
| 425 | + } else if (substr($path, 0, $rootLength) === $jailRoot . '/') { |
|
| 426 | + return $mount->getMountPoint() . substr($path, $rootLength); |
|
| 427 | + } else { |
|
| 428 | + return null; |
|
| 429 | + } |
|
| 430 | + } else { |
|
| 431 | + return $mount->getMountPoint() . $path; |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | 434 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | if (!$this->isValidPath($path)) { |
| 56 | 56 | throw new NotPermittedException('Invalid path'); |
| 57 | 57 | } |
| 58 | - return $this->path . $this->normalizePath($path); |
|
| 58 | + return $this->path.$this->normalizePath($path); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | if ($path === $this->path) { |
| 70 | 70 | return '/'; |
| 71 | - } else if (strpos($path, $this->path . '/') !== 0) { |
|
| 71 | + } else if (strpos($path, $this->path.'/') !== 0) { |
|
| 72 | 72 | return null; |
| 73 | 73 | } else { |
| 74 | 74 | $path = substr($path, strlen($this->path)); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @return bool |
| 84 | 84 | */ |
| 85 | 85 | public function isSubNode($node) { |
| 86 | - return strpos($node->getPath(), $this->path . '/') === 0; |
|
| 86 | + return strpos($node->getPath(), $this->path.'/') === 0; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | public function getDirectoryListing() { |
| 96 | 96 | $folderContent = $this->view->getDirectoryContent($this->path); |
| 97 | 97 | |
| 98 | - return array_map(function (FileInfo $info) { |
|
| 98 | + return array_map(function(FileInfo $info) { |
|
| 99 | 99 | if ($info->getMimetype() === 'httpd/unix-directory') { |
| 100 | 100 | return new Folder($this->root, $this->view, $info->getPath(), $info); |
| 101 | 101 | } else { |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public function search($query) { |
| 198 | 198 | if (is_string($query)) { |
| 199 | - return $this->searchCommon('search', array('%' . $query . '%')); |
|
| 199 | + return $this->searchCommon('search', array('%'.$query.'%')); |
|
| 200 | 200 | } else { |
| 201 | 201 | return $this->searchCommon('searchQuery', array($query)); |
| 202 | 202 | } |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $internalPath = $mount->getInternalPath($this->path); |
| 237 | 237 | $internalPath = rtrim($internalPath, '/'); |
| 238 | 238 | if ($internalPath !== '') { |
| 239 | - $internalPath = $internalPath . '/'; |
|
| 239 | + $internalPath = $internalPath.'/'; |
|
| 240 | 240 | } |
| 241 | 241 | $internalRootLength = strlen($internalPath); |
| 242 | 242 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | $result['internalPath'] = $result['path']; |
| 249 | 249 | $result['path'] = substr($result['path'], $internalRootLength); |
| 250 | 250 | $result['storage'] = $storage; |
| 251 | - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 251 | + $files[] = new \OC\Files\FileInfo($this->path.'/'.$result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | |
@@ -262,14 +262,14 @@ discard block |
||
| 262 | 262 | $results = call_user_func_array(array($cache, $method), $args); |
| 263 | 263 | foreach ($results as $result) { |
| 264 | 264 | $result['internalPath'] = $result['path']; |
| 265 | - $result['path'] = $relativeMountPoint . $result['path']; |
|
| 265 | + $result['path'] = $relativeMountPoint.$result['path']; |
|
| 266 | 266 | $result['storage'] = $storage; |
| 267 | - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 267 | + $files[] = new \OC\Files\FileInfo($this->path.'/'.$result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - return array_map(function (FileInfo $file) { |
|
| 272 | + return array_map(function(FileInfo $file) { |
|
| 273 | 273 | return $this->createNode($file->getPath(), $file); |
| 274 | 274 | }, $files); |
| 275 | 275 | } |
@@ -285,16 +285,16 @@ discard block |
||
| 285 | 285 | } else { |
| 286 | 286 | $user = null; |
| 287 | 287 | } |
| 288 | - $mountsContainingFile = $mountCache->getMountsForFileId((int)$id, $user); |
|
| 288 | + $mountsContainingFile = $mountCache->getMountsForFileId((int) $id, $user); |
|
| 289 | 289 | $mounts = $this->root->getMountsIn($this->path); |
| 290 | 290 | $mounts[] = $this->root->getMount($this->path); |
| 291 | 291 | /** @var IMountPoint[] $folderMounts */ |
| 292 | - $folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) { |
|
| 292 | + $folderMounts = array_combine(array_map(function(IMountPoint $mountPoint) { |
|
| 293 | 293 | return $mountPoint->getMountPoint(); |
| 294 | 294 | }, $mounts), $mounts); |
| 295 | 295 | |
| 296 | 296 | /** @var ICachedMountInfo[] $mountsContainingFile */ |
| 297 | - $mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) { |
|
| 297 | + $mountsContainingFile = array_values(array_filter($mountsContainingFile, function(ICachedMountInfo $cachedMountInfo) use ($folderMounts) { |
|
| 298 | 298 | return isset($folderMounts[$cachedMountInfo->getMountPoint()]); |
| 299 | 299 | })); |
| 300 | 300 | |
@@ -305,25 +305,25 @@ discard block |
||
| 305 | 305 | // we only need to get the cache info once, since all mounts we found point to the same storage |
| 306 | 306 | |
| 307 | 307 | $mount = $folderMounts[$mountsContainingFile[0]->getMountPoint()]; |
| 308 | - $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); |
|
| 308 | + $cacheEntry = $mount->getStorage()->getCache()->get((int) $id); |
|
| 309 | 309 | if (!$cacheEntry) { |
| 310 | 310 | return []; |
| 311 | 311 | } |
| 312 | 312 | // cache jails will hide the "true" internal path |
| 313 | - $internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); |
|
| 313 | + $internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath().'/'.$cacheEntry->getPath(), '/'); |
|
| 314 | 314 | |
| 315 | - $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) { |
|
| 315 | + $nodes = array_map(function(ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) { |
|
| 316 | 316 | $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; |
| 317 | 317 | $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); |
| 318 | 318 | $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); |
| 319 | - $absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount; |
|
| 319 | + $absolutePath = $cachedMountInfo->getMountPoint().$pathRelativeToMount; |
|
| 320 | 320 | return $this->root->createNode($absolutePath, new \OC\Files\FileInfo( |
| 321 | 321 | $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount, |
| 322 | 322 | \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount)) |
| 323 | 323 | )); |
| 324 | 324 | }, $mountsContainingFile); |
| 325 | 325 | |
| 326 | - return array_filter($nodes, function (Node $node) { |
|
| 326 | + return array_filter($nodes, function(Node $node) { |
|
| 327 | 327 | return $this->getRelativePath($node->getPath()); |
| 328 | 328 | }); |
| 329 | 329 | } |
@@ -367,10 +367,10 @@ discard block |
||
| 367 | 367 | $mounts = $this->root->getMountsIn($this->path); |
| 368 | 368 | $mounts[] = $this->getMountPoint(); |
| 369 | 369 | |
| 370 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 370 | + $mounts = array_filter($mounts, function(IMountPoint $mount) { |
|
| 371 | 371 | return $mount->getStorage(); |
| 372 | 372 | }); |
| 373 | - $storageIds = array_map(function (IMountPoint $mount) { |
|
| 373 | + $storageIds = array_map(function(IMountPoint $mount) { |
|
| 374 | 374 | return $mount->getStorage()->getCache()->getNumericStorageId(); |
| 375 | 375 | }, $mounts); |
| 376 | 376 | /** @var IMountPoint[] $mountMap */ |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | |
| 396 | 396 | $result = $query->execute()->fetchAll(); |
| 397 | 397 | |
| 398 | - $files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { |
|
| 398 | + $files = array_filter(array_map(function(array $entry) use ($mountMap, $mimetypeLoader) { |
|
| 399 | 399 | $mount = $mountMap[$entry['storage']]; |
| 400 | 400 | $entry['internalPath'] = $entry['path']; |
| 401 | 401 | $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']); |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | return $this->root->createNode($fileInfo->getPath(), $fileInfo); |
| 409 | 409 | }, $result)); |
| 410 | 410 | |
| 411 | - return array_values(array_filter($files, function (Node $node) { |
|
| 411 | + return array_values(array_filter($files, function(Node $node) { |
|
| 412 | 412 | $relative = $this->getRelativePath($node->getPath()); |
| 413 | 413 | return $relative !== null && $relative !== '/'; |
| 414 | 414 | })); |
@@ -422,13 +422,13 @@ discard block |
||
| 422 | 422 | $rootLength = strlen($jailRoot) + 1; |
| 423 | 423 | if ($path === $jailRoot) { |
| 424 | 424 | return $mount->getMountPoint(); |
| 425 | - } else if (substr($path, 0, $rootLength) === $jailRoot . '/') { |
|
| 426 | - return $mount->getMountPoint() . substr($path, $rootLength); |
|
| 425 | + } else if (substr($path, 0, $rootLength) === $jailRoot.'/') { |
|
| 426 | + return $mount->getMountPoint().substr($path, $rootLength); |
|
| 427 | 427 | } else { |
| 428 | 428 | return null; |
| 429 | 429 | } |
| 430 | 430 | } else { |
| 431 | - return $mount->getMountPoint() . $path; |
|
| 431 | + return $mount->getMountPoint().$path; |
|
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | 434 | } |
@@ -44,295 +44,295 @@ |
||
| 44 | 44 | * Cache mounts points per user in the cache so we can easilly look them up |
| 45 | 45 | */ |
| 46 | 46 | class UserMountCache implements IUserMountCache { |
| 47 | - /** |
|
| 48 | - * @var IDBConnection |
|
| 49 | - */ |
|
| 50 | - private $connection; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var IUserManager |
|
| 54 | - */ |
|
| 55 | - private $userManager; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Cached mount info. |
|
| 59 | - * Map of $userId to ICachedMountInfo. |
|
| 60 | - * |
|
| 61 | - * @var ICache |
|
| 62 | - **/ |
|
| 63 | - private $mountsForUsers; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var ILogger |
|
| 67 | - */ |
|
| 68 | - private $logger; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var ICache |
|
| 72 | - */ |
|
| 73 | - private $cacheInfoCache; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * UserMountCache constructor. |
|
| 77 | - * |
|
| 78 | - * @param IDBConnection $connection |
|
| 79 | - * @param IUserManager $userManager |
|
| 80 | - * @param ILogger $logger |
|
| 81 | - */ |
|
| 82 | - public function __construct(IDBConnection $connection, IUserManager $userManager, ILogger $logger) { |
|
| 83 | - $this->connection = $connection; |
|
| 84 | - $this->userManager = $userManager; |
|
| 85 | - $this->logger = $logger; |
|
| 86 | - $this->cacheInfoCache = new CappedMemoryCache(); |
|
| 87 | - $this->mountsForUsers = new CappedMemoryCache(); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - public function registerMounts(IUser $user, array $mounts) { |
|
| 91 | - // filter out non-proper storages coming from unit tests |
|
| 92 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 93 | - return $mount instanceof SharedMount || $mount->getStorage() && $mount->getStorage()->getCache(); |
|
| 94 | - }); |
|
| 95 | - /** @var ICachedMountInfo[] $newMounts */ |
|
| 96 | - $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
| 97 | - // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
|
| 98 | - if ($mount->getStorageRootId() === -1) { |
|
| 99 | - return null; |
|
| 100 | - } else { |
|
| 101 | - return new LazyStorageMountInfo($user, $mount); |
|
| 102 | - } |
|
| 103 | - }, $mounts); |
|
| 104 | - $newMounts = array_values(array_filter($newMounts)); |
|
| 105 | - |
|
| 106 | - $cachedMounts = $this->getMountsForUser($user); |
|
| 107 | - $mountDiff = function (ICachedMountInfo $mount1, ICachedMountInfo $mount2) { |
|
| 108 | - // since we are only looking for mounts for a specific user comparing on root id is enough |
|
| 109 | - return $mount1->getRootId() - $mount2->getRootId(); |
|
| 110 | - }; |
|
| 111 | - |
|
| 112 | - /** @var ICachedMountInfo[] $addedMounts */ |
|
| 113 | - $addedMounts = array_udiff($newMounts, $cachedMounts, $mountDiff); |
|
| 114 | - /** @var ICachedMountInfo[] $removedMounts */ |
|
| 115 | - $removedMounts = array_udiff($cachedMounts, $newMounts, $mountDiff); |
|
| 116 | - |
|
| 117 | - $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts); |
|
| 118 | - |
|
| 119 | - foreach ($addedMounts as $mount) { |
|
| 120 | - $this->addToCache($mount); |
|
| 121 | - $this->mountsForUsers[$user->getUID()][] = $mount; |
|
| 122 | - } |
|
| 123 | - foreach ($removedMounts as $mount) { |
|
| 124 | - $this->removeFromCache($mount); |
|
| 125 | - $index = array_search($mount, $this->mountsForUsers[$user->getUID()]); |
|
| 126 | - unset($this->mountsForUsers[$user->getUID()][$index]); |
|
| 127 | - } |
|
| 128 | - foreach ($changedMounts as $mount) { |
|
| 129 | - $this->updateCachedMount($mount); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param ICachedMountInfo[] $newMounts |
|
| 135 | - * @param ICachedMountInfo[] $cachedMounts |
|
| 136 | - * @return ICachedMountInfo[] |
|
| 137 | - */ |
|
| 138 | - private function findChangedMounts(array $newMounts, array $cachedMounts) { |
|
| 139 | - $changed = []; |
|
| 140 | - foreach ($newMounts as $newMount) { |
|
| 141 | - foreach ($cachedMounts as $cachedMount) { |
|
| 142 | - if ( |
|
| 143 | - $newMount->getRootId() === $cachedMount->getRootId() && |
|
| 144 | - ( |
|
| 145 | - $newMount->getMountPoint() !== $cachedMount->getMountPoint() || |
|
| 146 | - $newMount->getStorageId() !== $cachedMount->getStorageId() || |
|
| 147 | - $newMount->getMountId() !== $cachedMount->getMountId() |
|
| 148 | - ) |
|
| 149 | - ) { |
|
| 150 | - $changed[] = $newMount; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - return $changed; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - private function addToCache(ICachedMountInfo $mount) { |
|
| 158 | - if ($mount->getStorageId() !== -1) { |
|
| 159 | - $this->connection->insertIfNotExist('*PREFIX*mounts', [ |
|
| 160 | - 'storage_id' => $mount->getStorageId(), |
|
| 161 | - 'root_id' => $mount->getRootId(), |
|
| 162 | - 'user_id' => $mount->getUser()->getUID(), |
|
| 163 | - 'mount_point' => $mount->getMountPoint(), |
|
| 164 | - 'mount_id' => $mount->getMountId() |
|
| 165 | - ], ['root_id', 'user_id']); |
|
| 166 | - } else { |
|
| 167 | - // in some cases this is legitimate, like orphaned shares |
|
| 168 | - $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - private function updateCachedMount(ICachedMountInfo $mount) { |
|
| 173 | - $builder = $this->connection->getQueryBuilder(); |
|
| 174 | - |
|
| 175 | - $query = $builder->update('mounts') |
|
| 176 | - ->set('storage_id', $builder->createNamedParameter($mount->getStorageId())) |
|
| 177 | - ->set('mount_point', $builder->createNamedParameter($mount->getMountPoint())) |
|
| 178 | - ->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT)) |
|
| 179 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 180 | - ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
| 181 | - |
|
| 182 | - $query->execute(); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - private function removeFromCache(ICachedMountInfo $mount) { |
|
| 186 | - $builder = $this->connection->getQueryBuilder(); |
|
| 187 | - |
|
| 188 | - $query = $builder->delete('mounts') |
|
| 189 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 190 | - ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
| 191 | - $query->execute(); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - private function dbRowToMountInfo(array $row) { |
|
| 195 | - $user = $this->userManager->get($row['user_id']); |
|
| 196 | - if (is_null($user)) { |
|
| 197 | - return null; |
|
| 198 | - } |
|
| 199 | - return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $row['mount_id'], isset($row['path'])? $row['path']:''); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @param IUser $user |
|
| 204 | - * @return ICachedMountInfo[] |
|
| 205 | - */ |
|
| 206 | - public function getMountsForUser(IUser $user) { |
|
| 207 | - if (!isset($this->mountsForUsers[$user->getUID()])) { |
|
| 208 | - $builder = $this->connection->getQueryBuilder(); |
|
| 209 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
| 210 | - ->from('mounts', 'm') |
|
| 211 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 212 | - ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID()))); |
|
| 213 | - |
|
| 214 | - $rows = $query->execute()->fetchAll(); |
|
| 215 | - |
|
| 216 | - $this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 217 | - } |
|
| 218 | - return $this->mountsForUsers[$user->getUID()]; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * @param int $numericStorageId |
|
| 223 | - * @param string|null $user limit the results to a single user |
|
| 224 | - * @return CachedMountInfo[] |
|
| 225 | - */ |
|
| 226 | - public function getMountsForStorageId($numericStorageId, $user = null) { |
|
| 227 | - $builder = $this->connection->getQueryBuilder(); |
|
| 228 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
| 229 | - ->from('mounts', 'm') |
|
| 230 | - ->innerJoin('m', 'filecache', 'f' , $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 231 | - ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); |
|
| 232 | - |
|
| 233 | - if ($user) { |
|
| 234 | - $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - $rows = $query->execute()->fetchAll(); |
|
| 238 | - |
|
| 239 | - return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param int $rootFileId |
|
| 244 | - * @return CachedMountInfo[] |
|
| 245 | - */ |
|
| 246 | - public function getMountsForRootId($rootFileId) { |
|
| 247 | - $builder = $this->connection->getQueryBuilder(); |
|
| 248 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
| 249 | - ->from('mounts', 'm') |
|
| 250 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 251 | - ->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT))); |
|
| 252 | - |
|
| 253 | - $rows = $query->execute()->fetchAll(); |
|
| 254 | - |
|
| 255 | - return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * @param $fileId |
|
| 260 | - * @return array |
|
| 261 | - * @throws \OCP\Files\NotFoundException |
|
| 262 | - */ |
|
| 263 | - private function getCacheInfoFromFileId($fileId) { |
|
| 264 | - if (!isset($this->cacheInfoCache[$fileId])) { |
|
| 265 | - $builder = $this->connection->getQueryBuilder(); |
|
| 266 | - $query = $builder->select('storage', 'path', 'mimetype') |
|
| 267 | - ->from('filecache') |
|
| 268 | - ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); |
|
| 269 | - |
|
| 270 | - $row = $query->execute()->fetch(); |
|
| 271 | - if (is_array($row)) { |
|
| 272 | - $this->cacheInfoCache[$fileId] = [ |
|
| 273 | - (int)$row['storage'], |
|
| 274 | - $row['path'], |
|
| 275 | - (int)$row['mimetype'] |
|
| 276 | - ]; |
|
| 277 | - } else { |
|
| 278 | - throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - return $this->cacheInfoCache[$fileId]; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * @param int $fileId |
|
| 286 | - * @param string|null $user optionally restrict the results to a single user |
|
| 287 | - * @return ICachedMountInfo[] |
|
| 288 | - * @since 9.0.0 |
|
| 289 | - */ |
|
| 290 | - public function getMountsForFileId($fileId, $user = null) { |
|
| 291 | - try { |
|
| 292 | - list($storageId, $internalPath) = $this->getCacheInfoFromFileId($fileId); |
|
| 293 | - } catch (NotFoundException $e) { |
|
| 294 | - return []; |
|
| 295 | - } |
|
| 296 | - $mountsForStorage = $this->getMountsForStorageId($storageId, $user); |
|
| 297 | - |
|
| 298 | - // filter mounts that are from the same storage but a different directory |
|
| 299 | - return array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) { |
|
| 300 | - if ($fileId === $mount->getRootId()) { |
|
| 301 | - return true; |
|
| 302 | - } |
|
| 303 | - $internalMountPath = $mount->getRootInternalPath(); |
|
| 304 | - |
|
| 305 | - return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
| 306 | - }); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Remove all cached mounts for a user |
|
| 311 | - * |
|
| 312 | - * @param IUser $user |
|
| 313 | - */ |
|
| 314 | - public function removeUserMounts(IUser $user) { |
|
| 315 | - $builder = $this->connection->getQueryBuilder(); |
|
| 316 | - |
|
| 317 | - $query = $builder->delete('mounts') |
|
| 318 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID()))); |
|
| 319 | - $query->execute(); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - public function removeUserStorageMount($storageId, $userId) { |
|
| 323 | - $builder = $this->connection->getQueryBuilder(); |
|
| 324 | - |
|
| 325 | - $query = $builder->delete('mounts') |
|
| 326 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userId))) |
|
| 327 | - ->andWhere($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 328 | - $query->execute(); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - public function remoteStorageMounts($storageId) { |
|
| 332 | - $builder = $this->connection->getQueryBuilder(); |
|
| 333 | - |
|
| 334 | - $query = $builder->delete('mounts') |
|
| 335 | - ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 336 | - $query->execute(); |
|
| 337 | - } |
|
| 47 | + /** |
|
| 48 | + * @var IDBConnection |
|
| 49 | + */ |
|
| 50 | + private $connection; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var IUserManager |
|
| 54 | + */ |
|
| 55 | + private $userManager; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Cached mount info. |
|
| 59 | + * Map of $userId to ICachedMountInfo. |
|
| 60 | + * |
|
| 61 | + * @var ICache |
|
| 62 | + **/ |
|
| 63 | + private $mountsForUsers; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var ILogger |
|
| 67 | + */ |
|
| 68 | + private $logger; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var ICache |
|
| 72 | + */ |
|
| 73 | + private $cacheInfoCache; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * UserMountCache constructor. |
|
| 77 | + * |
|
| 78 | + * @param IDBConnection $connection |
|
| 79 | + * @param IUserManager $userManager |
|
| 80 | + * @param ILogger $logger |
|
| 81 | + */ |
|
| 82 | + public function __construct(IDBConnection $connection, IUserManager $userManager, ILogger $logger) { |
|
| 83 | + $this->connection = $connection; |
|
| 84 | + $this->userManager = $userManager; |
|
| 85 | + $this->logger = $logger; |
|
| 86 | + $this->cacheInfoCache = new CappedMemoryCache(); |
|
| 87 | + $this->mountsForUsers = new CappedMemoryCache(); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + public function registerMounts(IUser $user, array $mounts) { |
|
| 91 | + // filter out non-proper storages coming from unit tests |
|
| 92 | + $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 93 | + return $mount instanceof SharedMount || $mount->getStorage() && $mount->getStorage()->getCache(); |
|
| 94 | + }); |
|
| 95 | + /** @var ICachedMountInfo[] $newMounts */ |
|
| 96 | + $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
| 97 | + // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
|
| 98 | + if ($mount->getStorageRootId() === -1) { |
|
| 99 | + return null; |
|
| 100 | + } else { |
|
| 101 | + return new LazyStorageMountInfo($user, $mount); |
|
| 102 | + } |
|
| 103 | + }, $mounts); |
|
| 104 | + $newMounts = array_values(array_filter($newMounts)); |
|
| 105 | + |
|
| 106 | + $cachedMounts = $this->getMountsForUser($user); |
|
| 107 | + $mountDiff = function (ICachedMountInfo $mount1, ICachedMountInfo $mount2) { |
|
| 108 | + // since we are only looking for mounts for a specific user comparing on root id is enough |
|
| 109 | + return $mount1->getRootId() - $mount2->getRootId(); |
|
| 110 | + }; |
|
| 111 | + |
|
| 112 | + /** @var ICachedMountInfo[] $addedMounts */ |
|
| 113 | + $addedMounts = array_udiff($newMounts, $cachedMounts, $mountDiff); |
|
| 114 | + /** @var ICachedMountInfo[] $removedMounts */ |
|
| 115 | + $removedMounts = array_udiff($cachedMounts, $newMounts, $mountDiff); |
|
| 116 | + |
|
| 117 | + $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts); |
|
| 118 | + |
|
| 119 | + foreach ($addedMounts as $mount) { |
|
| 120 | + $this->addToCache($mount); |
|
| 121 | + $this->mountsForUsers[$user->getUID()][] = $mount; |
|
| 122 | + } |
|
| 123 | + foreach ($removedMounts as $mount) { |
|
| 124 | + $this->removeFromCache($mount); |
|
| 125 | + $index = array_search($mount, $this->mountsForUsers[$user->getUID()]); |
|
| 126 | + unset($this->mountsForUsers[$user->getUID()][$index]); |
|
| 127 | + } |
|
| 128 | + foreach ($changedMounts as $mount) { |
|
| 129 | + $this->updateCachedMount($mount); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param ICachedMountInfo[] $newMounts |
|
| 135 | + * @param ICachedMountInfo[] $cachedMounts |
|
| 136 | + * @return ICachedMountInfo[] |
|
| 137 | + */ |
|
| 138 | + private function findChangedMounts(array $newMounts, array $cachedMounts) { |
|
| 139 | + $changed = []; |
|
| 140 | + foreach ($newMounts as $newMount) { |
|
| 141 | + foreach ($cachedMounts as $cachedMount) { |
|
| 142 | + if ( |
|
| 143 | + $newMount->getRootId() === $cachedMount->getRootId() && |
|
| 144 | + ( |
|
| 145 | + $newMount->getMountPoint() !== $cachedMount->getMountPoint() || |
|
| 146 | + $newMount->getStorageId() !== $cachedMount->getStorageId() || |
|
| 147 | + $newMount->getMountId() !== $cachedMount->getMountId() |
|
| 148 | + ) |
|
| 149 | + ) { |
|
| 150 | + $changed[] = $newMount; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + return $changed; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + private function addToCache(ICachedMountInfo $mount) { |
|
| 158 | + if ($mount->getStorageId() !== -1) { |
|
| 159 | + $this->connection->insertIfNotExist('*PREFIX*mounts', [ |
|
| 160 | + 'storage_id' => $mount->getStorageId(), |
|
| 161 | + 'root_id' => $mount->getRootId(), |
|
| 162 | + 'user_id' => $mount->getUser()->getUID(), |
|
| 163 | + 'mount_point' => $mount->getMountPoint(), |
|
| 164 | + 'mount_id' => $mount->getMountId() |
|
| 165 | + ], ['root_id', 'user_id']); |
|
| 166 | + } else { |
|
| 167 | + // in some cases this is legitimate, like orphaned shares |
|
| 168 | + $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + private function updateCachedMount(ICachedMountInfo $mount) { |
|
| 173 | + $builder = $this->connection->getQueryBuilder(); |
|
| 174 | + |
|
| 175 | + $query = $builder->update('mounts') |
|
| 176 | + ->set('storage_id', $builder->createNamedParameter($mount->getStorageId())) |
|
| 177 | + ->set('mount_point', $builder->createNamedParameter($mount->getMountPoint())) |
|
| 178 | + ->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT)) |
|
| 179 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 180 | + ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
| 181 | + |
|
| 182 | + $query->execute(); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + private function removeFromCache(ICachedMountInfo $mount) { |
|
| 186 | + $builder = $this->connection->getQueryBuilder(); |
|
| 187 | + |
|
| 188 | + $query = $builder->delete('mounts') |
|
| 189 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 190 | + ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
| 191 | + $query->execute(); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + private function dbRowToMountInfo(array $row) { |
|
| 195 | + $user = $this->userManager->get($row['user_id']); |
|
| 196 | + if (is_null($user)) { |
|
| 197 | + return null; |
|
| 198 | + } |
|
| 199 | + return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $row['mount_id'], isset($row['path'])? $row['path']:''); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @param IUser $user |
|
| 204 | + * @return ICachedMountInfo[] |
|
| 205 | + */ |
|
| 206 | + public function getMountsForUser(IUser $user) { |
|
| 207 | + if (!isset($this->mountsForUsers[$user->getUID()])) { |
|
| 208 | + $builder = $this->connection->getQueryBuilder(); |
|
| 209 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
| 210 | + ->from('mounts', 'm') |
|
| 211 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 212 | + ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID()))); |
|
| 213 | + |
|
| 214 | + $rows = $query->execute()->fetchAll(); |
|
| 215 | + |
|
| 216 | + $this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 217 | + } |
|
| 218 | + return $this->mountsForUsers[$user->getUID()]; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * @param int $numericStorageId |
|
| 223 | + * @param string|null $user limit the results to a single user |
|
| 224 | + * @return CachedMountInfo[] |
|
| 225 | + */ |
|
| 226 | + public function getMountsForStorageId($numericStorageId, $user = null) { |
|
| 227 | + $builder = $this->connection->getQueryBuilder(); |
|
| 228 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
| 229 | + ->from('mounts', 'm') |
|
| 230 | + ->innerJoin('m', 'filecache', 'f' , $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 231 | + ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); |
|
| 232 | + |
|
| 233 | + if ($user) { |
|
| 234 | + $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + $rows = $query->execute()->fetchAll(); |
|
| 238 | + |
|
| 239 | + return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param int $rootFileId |
|
| 244 | + * @return CachedMountInfo[] |
|
| 245 | + */ |
|
| 246 | + public function getMountsForRootId($rootFileId) { |
|
| 247 | + $builder = $this->connection->getQueryBuilder(); |
|
| 248 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
| 249 | + ->from('mounts', 'm') |
|
| 250 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 251 | + ->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT))); |
|
| 252 | + |
|
| 253 | + $rows = $query->execute()->fetchAll(); |
|
| 254 | + |
|
| 255 | + return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * @param $fileId |
|
| 260 | + * @return array |
|
| 261 | + * @throws \OCP\Files\NotFoundException |
|
| 262 | + */ |
|
| 263 | + private function getCacheInfoFromFileId($fileId) { |
|
| 264 | + if (!isset($this->cacheInfoCache[$fileId])) { |
|
| 265 | + $builder = $this->connection->getQueryBuilder(); |
|
| 266 | + $query = $builder->select('storage', 'path', 'mimetype') |
|
| 267 | + ->from('filecache') |
|
| 268 | + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); |
|
| 269 | + |
|
| 270 | + $row = $query->execute()->fetch(); |
|
| 271 | + if (is_array($row)) { |
|
| 272 | + $this->cacheInfoCache[$fileId] = [ |
|
| 273 | + (int)$row['storage'], |
|
| 274 | + $row['path'], |
|
| 275 | + (int)$row['mimetype'] |
|
| 276 | + ]; |
|
| 277 | + } else { |
|
| 278 | + throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + return $this->cacheInfoCache[$fileId]; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * @param int $fileId |
|
| 286 | + * @param string|null $user optionally restrict the results to a single user |
|
| 287 | + * @return ICachedMountInfo[] |
|
| 288 | + * @since 9.0.0 |
|
| 289 | + */ |
|
| 290 | + public function getMountsForFileId($fileId, $user = null) { |
|
| 291 | + try { |
|
| 292 | + list($storageId, $internalPath) = $this->getCacheInfoFromFileId($fileId); |
|
| 293 | + } catch (NotFoundException $e) { |
|
| 294 | + return []; |
|
| 295 | + } |
|
| 296 | + $mountsForStorage = $this->getMountsForStorageId($storageId, $user); |
|
| 297 | + |
|
| 298 | + // filter mounts that are from the same storage but a different directory |
|
| 299 | + return array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) { |
|
| 300 | + if ($fileId === $mount->getRootId()) { |
|
| 301 | + return true; |
|
| 302 | + } |
|
| 303 | + $internalMountPath = $mount->getRootInternalPath(); |
|
| 304 | + |
|
| 305 | + return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
| 306 | + }); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Remove all cached mounts for a user |
|
| 311 | + * |
|
| 312 | + * @param IUser $user |
|
| 313 | + */ |
|
| 314 | + public function removeUserMounts(IUser $user) { |
|
| 315 | + $builder = $this->connection->getQueryBuilder(); |
|
| 316 | + |
|
| 317 | + $query = $builder->delete('mounts') |
|
| 318 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID()))); |
|
| 319 | + $query->execute(); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + public function removeUserStorageMount($storageId, $userId) { |
|
| 323 | + $builder = $this->connection->getQueryBuilder(); |
|
| 324 | + |
|
| 325 | + $query = $builder->delete('mounts') |
|
| 326 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userId))) |
|
| 327 | + ->andWhere($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 328 | + $query->execute(); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + public function remoteStorageMounts($storageId) { |
|
| 332 | + $builder = $this->connection->getQueryBuilder(); |
|
| 333 | + |
|
| 334 | + $query = $builder->delete('mounts') |
|
| 335 | + ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 336 | + $query->execute(); |
|
| 337 | + } |
|
| 338 | 338 | } |
@@ -89,11 +89,11 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | public function registerMounts(IUser $user, array $mounts) { |
| 91 | 91 | // filter out non-proper storages coming from unit tests |
| 92 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 92 | + $mounts = array_filter($mounts, function(IMountPoint $mount) { |
|
| 93 | 93 | return $mount instanceof SharedMount || $mount->getStorage() && $mount->getStorage()->getCache(); |
| 94 | 94 | }); |
| 95 | 95 | /** @var ICachedMountInfo[] $newMounts */ |
| 96 | - $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
| 96 | + $newMounts = array_map(function(IMountPoint $mount) use ($user) { |
|
| 97 | 97 | // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
| 98 | 98 | if ($mount->getStorageRootId() === -1) { |
| 99 | 99 | return null; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $newMounts = array_values(array_filter($newMounts)); |
| 105 | 105 | |
| 106 | 106 | $cachedMounts = $this->getMountsForUser($user); |
| 107 | - $mountDiff = function (ICachedMountInfo $mount1, ICachedMountInfo $mount2) { |
|
| 107 | + $mountDiff = function(ICachedMountInfo $mount1, ICachedMountInfo $mount2) { |
|
| 108 | 108 | // since we are only looking for mounts for a specific user comparing on root id is enough |
| 109 | 109 | return $mount1->getRootId() - $mount2->getRootId(); |
| 110 | 110 | }; |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | ], ['root_id', 'user_id']); |
| 166 | 166 | } else { |
| 167 | 167 | // in some cases this is legitimate, like orphaned shares |
| 168 | - $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
| 168 | + $this->logger->debug('Could not get storage info for mount at '.$mount->getMountPoint()); |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | if (is_null($user)) { |
| 197 | 197 | return null; |
| 198 | 198 | } |
| 199 | - return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $row['mount_id'], isset($row['path'])? $row['path']:''); |
|
| 199 | + return new CachedMountInfo($user, (int) $row['storage_id'], (int) $row['root_id'], $row['mount_point'], $row['mount_id'], isset($row['path']) ? $row['path'] : ''); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $builder = $this->connection->getQueryBuilder(); |
| 228 | 228 | $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
| 229 | 229 | ->from('mounts', 'm') |
| 230 | - ->innerJoin('m', 'filecache', 'f' , $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 230 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 231 | 231 | ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); |
| 232 | 232 | |
| 233 | 233 | if ($user) { |
@@ -270,12 +270,12 @@ discard block |
||
| 270 | 270 | $row = $query->execute()->fetch(); |
| 271 | 271 | if (is_array($row)) { |
| 272 | 272 | $this->cacheInfoCache[$fileId] = [ |
| 273 | - (int)$row['storage'], |
|
| 273 | + (int) $row['storage'], |
|
| 274 | 274 | $row['path'], |
| 275 | - (int)$row['mimetype'] |
|
| 275 | + (int) $row['mimetype'] |
|
| 276 | 276 | ]; |
| 277 | 277 | } else { |
| 278 | - throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
| 278 | + throw new NotFoundException('File with id "'.$fileId.'" not found'); |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | return $this->cacheInfoCache[$fileId]; |
@@ -296,13 +296,13 @@ discard block |
||
| 296 | 296 | $mountsForStorage = $this->getMountsForStorageId($storageId, $user); |
| 297 | 297 | |
| 298 | 298 | // filter mounts that are from the same storage but a different directory |
| 299 | - return array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) { |
|
| 299 | + return array_filter($mountsForStorage, function(ICachedMountInfo $mount) use ($internalPath, $fileId) { |
|
| 300 | 300 | if ($fileId === $mount->getRootId()) { |
| 301 | 301 | return true; |
| 302 | 302 | } |
| 303 | 303 | $internalMountPath = $mount->getRootInternalPath(); |
| 304 | 304 | |
| 305 | - return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
| 305 | + return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath.'/'; |
|
| 306 | 306 | }); |
| 307 | 307 | } |
| 308 | 308 | |
@@ -31,77 +31,77 @@ |
||
| 31 | 31 | * @since 9.0.0 |
| 32 | 32 | */ |
| 33 | 33 | interface IUserMountCache { |
| 34 | - /** |
|
| 35 | - * Register mounts for a user to the cache |
|
| 36 | - * |
|
| 37 | - * @param IUser $user |
|
| 38 | - * @param IMountPoint[] $mounts |
|
| 39 | - * @since 9.0.0 |
|
| 40 | - */ |
|
| 41 | - public function registerMounts(IUser $user, array $mounts); |
|
| 34 | + /** |
|
| 35 | + * Register mounts for a user to the cache |
|
| 36 | + * |
|
| 37 | + * @param IUser $user |
|
| 38 | + * @param IMountPoint[] $mounts |
|
| 39 | + * @since 9.0.0 |
|
| 40 | + */ |
|
| 41 | + public function registerMounts(IUser $user, array $mounts); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Get all cached mounts for a user |
|
| 45 | - * |
|
| 46 | - * @param IUser $user |
|
| 47 | - * @return ICachedMountInfo[] |
|
| 48 | - * @since 9.0.0 |
|
| 49 | - */ |
|
| 50 | - public function getMountsForUser(IUser $user); |
|
| 43 | + /** |
|
| 44 | + * Get all cached mounts for a user |
|
| 45 | + * |
|
| 46 | + * @param IUser $user |
|
| 47 | + * @return ICachedMountInfo[] |
|
| 48 | + * @since 9.0.0 |
|
| 49 | + */ |
|
| 50 | + public function getMountsForUser(IUser $user); |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Get all cached mounts by storage |
|
| 54 | - * |
|
| 55 | - * @param int $numericStorageId |
|
| 56 | - * @param string|null $user limit the results to a single user @since 12.0.0 |
|
| 57 | - * @return ICachedMountInfo[] |
|
| 58 | - * @since 9.0.0 |
|
| 59 | - */ |
|
| 60 | - public function getMountsForStorageId($numericStorageId, $user = null); |
|
| 52 | + /** |
|
| 53 | + * Get all cached mounts by storage |
|
| 54 | + * |
|
| 55 | + * @param int $numericStorageId |
|
| 56 | + * @param string|null $user limit the results to a single user @since 12.0.0 |
|
| 57 | + * @return ICachedMountInfo[] |
|
| 58 | + * @since 9.0.0 |
|
| 59 | + */ |
|
| 60 | + public function getMountsForStorageId($numericStorageId, $user = null); |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Get all cached mounts by root |
|
| 64 | - * |
|
| 65 | - * @param int $rootFileId |
|
| 66 | - * @return ICachedMountInfo[] |
|
| 67 | - * @since 9.0.0 |
|
| 68 | - */ |
|
| 69 | - public function getMountsForRootId($rootFileId); |
|
| 62 | + /** |
|
| 63 | + * Get all cached mounts by root |
|
| 64 | + * |
|
| 65 | + * @param int $rootFileId |
|
| 66 | + * @return ICachedMountInfo[] |
|
| 67 | + * @since 9.0.0 |
|
| 68 | + */ |
|
| 69 | + public function getMountsForRootId($rootFileId); |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Get all cached mounts that contain a file |
|
| 73 | - * |
|
| 74 | - * @param int $fileId |
|
| 75 | - * @param string|null $user optionally restrict the results to a single user @since 12.0.0 |
|
| 76 | - * @return ICachedMountInfo[] |
|
| 77 | - * @since 9.0.0 |
|
| 78 | - */ |
|
| 79 | - public function getMountsForFileId($fileId, $user = null); |
|
| 71 | + /** |
|
| 72 | + * Get all cached mounts that contain a file |
|
| 73 | + * |
|
| 74 | + * @param int $fileId |
|
| 75 | + * @param string|null $user optionally restrict the results to a single user @since 12.0.0 |
|
| 76 | + * @return ICachedMountInfo[] |
|
| 77 | + * @since 9.0.0 |
|
| 78 | + */ |
|
| 79 | + public function getMountsForFileId($fileId, $user = null); |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Remove all cached mounts for a user |
|
| 83 | - * |
|
| 84 | - * @param IUser $user |
|
| 85 | - * @since 9.0.0 |
|
| 86 | - */ |
|
| 87 | - public function removeUserMounts(IUser $user); |
|
| 81 | + /** |
|
| 82 | + * Remove all cached mounts for a user |
|
| 83 | + * |
|
| 84 | + * @param IUser $user |
|
| 85 | + * @since 9.0.0 |
|
| 86 | + */ |
|
| 87 | + public function removeUserMounts(IUser $user); |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Remove all mounts for a user and storage |
|
| 91 | - * |
|
| 92 | - * @param $storageId |
|
| 93 | - * @param string $userId |
|
| 94 | - * @return mixed |
|
| 95 | - * @since 9.0.0 |
|
| 96 | - */ |
|
| 97 | - public function removeUserStorageMount($storageId, $userId); |
|
| 89 | + /** |
|
| 90 | + * Remove all mounts for a user and storage |
|
| 91 | + * |
|
| 92 | + * @param $storageId |
|
| 93 | + * @param string $userId |
|
| 94 | + * @return mixed |
|
| 95 | + * @since 9.0.0 |
|
| 96 | + */ |
|
| 97 | + public function removeUserStorageMount($storageId, $userId); |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Remove all cached mounts for a storage |
|
| 101 | - * |
|
| 102 | - * @param $storageId |
|
| 103 | - * @return mixed |
|
| 104 | - * @since 9.0.0 |
|
| 105 | - */ |
|
| 106 | - public function remoteStorageMounts($storageId); |
|
| 99 | + /** |
|
| 100 | + * Remove all cached mounts for a storage |
|
| 101 | + * |
|
| 102 | + * @param $storageId |
|
| 103 | + * @return mixed |
|
| 104 | + * @since 9.0.0 |
|
| 105 | + */ |
|
| 106 | + public function remoteStorageMounts($storageId); |
|
| 107 | 107 | } |