| @@ -37,479 +37,479 @@ | ||
| 37 | 37 | use OCP\Files\Search\ISearchOperator; | 
| 38 | 38 | |
| 39 | 39 |  class Folder extends Node implements \OCP\Files\Folder { | 
| 40 | - /** | |
| 41 | - * Creates a Folder that represents a non-existing path | |
| 42 | - * | |
| 43 | - * @param string $path path | |
| 44 | - * @return string non-existing node class | |
| 45 | - */ | |
| 46 | -	protected function createNonExistingNode($path) { | |
| 47 | - return new NonExistingFolder($this->root, $this->view, $path); | |
| 48 | - } | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * @param string $path path relative to the folder | |
| 52 | - * @return string | |
| 53 | - * @throws \OCP\Files\NotPermittedException | |
| 54 | - */ | |
| 55 | -	public function getFullPath($path) { | |
| 56 | -		if (!$this->isValidPath($path)) { | |
| 57 | -			throw new NotPermittedException('Invalid path'); | |
| 58 | - } | |
| 59 | - return $this->path . $this->normalizePath($path); | |
| 60 | - } | |
| 61 | - | |
| 62 | - /** | |
| 63 | - * @param string $path | |
| 64 | - * @return string | |
| 65 | - */ | |
| 66 | -	public function getRelativePath($path) { | |
| 67 | -		if ($this->path === '' or $this->path === '/') { | |
| 68 | - return $this->normalizePath($path); | |
| 69 | - } | |
| 70 | -		if ($path === $this->path) { | |
| 71 | - return '/'; | |
| 72 | -		} else if (strpos($path, $this->path . '/') !== 0) { | |
| 73 | - return null; | |
| 74 | -		} else { | |
| 75 | - $path = substr($path, strlen($this->path)); | |
| 76 | - return $this->normalizePath($path); | |
| 77 | - } | |
| 78 | - } | |
| 79 | - | |
| 80 | - /** | |
| 81 | - * check if a node is a (grand-)child of the folder | |
| 82 | - * | |
| 83 | - * @param \OC\Files\Node\Node $node | |
| 84 | - * @return bool | |
| 85 | - */ | |
| 86 | -	public function isSubNode($node) { | |
| 87 | - return strpos($node->getPath(), $this->path . '/') === 0; | |
| 88 | - } | |
| 89 | - | |
| 90 | - /** | |
| 91 | - * get the content of this directory | |
| 92 | - * | |
| 93 | - * @throws \OCP\Files\NotFoundException | |
| 94 | - * @return Node[] | |
| 95 | - */ | |
| 96 | -	public function getDirectoryListing() { | |
| 97 | - $folderContent = $this->view->getDirectoryContent($this->path); | |
| 98 | - | |
| 99 | -		return array_map(function (FileInfo $info) { | |
| 100 | -			if ($info->getMimetype() === 'httpd/unix-directory') { | |
| 101 | - return new Folder($this->root, $this->view, $info->getPath(), $info); | |
| 102 | -			} else { | |
| 103 | - return new File($this->root, $this->view, $info->getPath(), $info); | |
| 104 | - } | |
| 105 | - }, $folderContent); | |
| 106 | - } | |
| 107 | - | |
| 108 | - /** | |
| 109 | - * @param string $path | |
| 110 | - * @param FileInfo $info | |
| 111 | - * @return File|Folder | |
| 112 | - */ | |
| 113 | -	protected function createNode($path, FileInfo $info = null) { | |
| 114 | -		if (is_null($info)) { | |
| 115 | - $isDir = $this->view->is_dir($path); | |
| 116 | -		} else { | |
| 117 | - $isDir = $info->getType() === FileInfo::TYPE_FOLDER; | |
| 118 | - } | |
| 119 | -		if ($isDir) { | |
| 120 | - return new Folder($this->root, $this->view, $path, $info); | |
| 121 | -		} else { | |
| 122 | - return new File($this->root, $this->view, $path, $info); | |
| 123 | - } | |
| 124 | - } | |
| 125 | - | |
| 126 | - /** | |
| 127 | - * Get the node at $path | |
| 128 | - * | |
| 129 | - * @param string $path | |
| 130 | - * @return \OC\Files\Node\Node | |
| 131 | - * @throws \OCP\Files\NotFoundException | |
| 132 | - */ | |
| 133 | -	public function get($path) { | |
| 134 | - return $this->root->get($this->getFullPath($path)); | |
| 135 | - } | |
| 136 | - | |
| 137 | - /** | |
| 138 | - * @param string $path | |
| 139 | - * @return bool | |
| 140 | - */ | |
| 141 | -	public function nodeExists($path) { | |
| 142 | -		try { | |
| 143 | - $this->get($path); | |
| 144 | - return true; | |
| 145 | -		} catch (NotFoundException $e) { | |
| 146 | - return false; | |
| 147 | - } | |
| 148 | - } | |
| 149 | - | |
| 150 | - /** | |
| 151 | - * @param string $path | |
| 152 | - * @return \OC\Files\Node\Folder | |
| 153 | - * @throws \OCP\Files\NotPermittedException | |
| 154 | - */ | |
| 155 | -	public function newFolder($path) { | |
| 156 | -		if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { | |
| 157 | - $fullPath = $this->getFullPath($path); | |
| 158 | - $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); | |
| 159 | - $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]); | |
| 160 | -			if(!$this->view->mkdir($fullPath)) { | |
| 161 | -				throw new NotPermittedException('Could not create folder'); | |
| 162 | - } | |
| 163 | - $node = new Folder($this->root, $this->view, $fullPath); | |
| 164 | - $this->sendHooks(['postWrite', 'postCreate'], [$node]); | |
| 165 | - return $node; | |
| 166 | -		} else { | |
| 167 | -			throw new NotPermittedException('No create permission for folder'); | |
| 168 | - } | |
| 169 | - } | |
| 170 | - | |
| 171 | - /** | |
| 172 | - * @param string $path | |
| 173 | - * @return \OC\Files\Node\File | |
| 174 | - * @throws \OCP\Files\NotPermittedException | |
| 175 | - */ | |
| 176 | -	public function newFile($path) { | |
| 177 | -		if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { | |
| 178 | - $fullPath = $this->getFullPath($path); | |
| 179 | - $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); | |
| 180 | - $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]); | |
| 181 | -			if (!$this->view->touch($fullPath)) { | |
| 182 | -				throw new NotPermittedException('Could not create path'); | |
| 183 | - } | |
| 184 | - $node = new File($this->root, $this->view, $fullPath); | |
| 185 | - $this->sendHooks(['postWrite', 'postCreate'], [$node]); | |
| 186 | - return $node; | |
| 187 | - } | |
| 188 | -		throw new NotPermittedException('No create permission for path'); | |
| 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 = ltrim(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 | -			if ($user === $this->getAppDataDirectoryName()) { | |
| 303 | - return $this->getByIdInRootMount((int) $id); | |
| 304 | - } | |
| 305 | - return []; | |
| 306 | - } | |
| 307 | - | |
| 308 | -		$nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($folderMounts, $id) { | |
| 309 | - $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; | |
| 310 | - $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); | |
| 311 | -			if (!$cacheEntry) { | |
| 312 | - return null; | |
| 313 | - } | |
| 314 | - | |
| 315 | - // cache jails will hide the "true" internal path | |
| 316 | - $internalPath = ltrim($cachedMountInfo->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); | |
| 317 | - $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); | |
| 318 | - $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); | |
| 319 | - $absolutePath = rtrim($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 | - $nodes = array_filter($nodes); | |
| 327 | - | |
| 328 | -		return array_filter($nodes, function (Node $node) { | |
| 329 | - return $this->getRelativePath($node->getPath()); | |
| 330 | - }); | |
| 331 | - } | |
| 332 | - | |
| 333 | -	protected function getAppDataDirectoryName(): string { | |
| 334 | -		$instanceId = \OC::$server->getConfig()->getSystemValueString('instanceid'); | |
| 335 | - return 'appdata_' . $instanceId; | |
| 336 | - } | |
| 337 | - | |
| 338 | - /** | |
| 339 | - * In case the path we are currently in is inside the appdata_* folder, | |
| 340 | - * the original getById method does not work, because it can only look inside | |
| 341 | - * the user's mount points. But the user has no mount point for the root storage. | |
| 342 | - * | |
| 343 | - * So in that case we directly check the mount of the root if it contains | |
| 344 | - * the id. If it does we check if the path is inside the path we are working | |
| 345 | - * in. | |
| 346 | - * | |
| 347 | - * @param int $id | |
| 348 | - * @return array | |
| 349 | - */ | |
| 350 | -	protected function getByIdInRootMount(int $id): array { | |
| 351 | -		$mount = $this->root->getMount(''); | |
| 352 | - $cacheEntry = $mount->getStorage()->getCache($this->path)->get($id); | |
| 353 | -		if (!$cacheEntry) { | |
| 354 | - return []; | |
| 355 | - } | |
| 356 | - | |
| 357 | - $absolutePath = '/' . ltrim($cacheEntry->getPath(), '/'); | |
| 358 | - $currentPath = rtrim($this->path, '/') . '/'; | |
| 359 | - | |
| 360 | -		if (strpos($absolutePath, $currentPath) !== 0) { | |
| 361 | - return []; | |
| 362 | - } | |
| 363 | - | |
| 364 | - return [$this->root->createNode( | |
| 365 | - $absolutePath, new \OC\Files\FileInfo( | |
| 366 | - $absolutePath, | |
| 367 | - $mount->getStorage(), | |
| 368 | - $cacheEntry->getPath(), | |
| 369 | - $cacheEntry, | |
| 370 | - $mount | |
| 371 | - ))]; | |
| 372 | - } | |
| 373 | - | |
| 374 | -	public function getFreeSpace() { | |
| 375 | - return $this->view->free_space($this->path); | |
| 376 | - } | |
| 377 | - | |
| 378 | -	public function delete() { | |
| 379 | -		if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { | |
| 380 | -			$this->sendHooks(array('preDelete')); | |
| 381 | - $fileInfo = $this->getFileInfo(); | |
| 382 | - $this->view->rmdir($this->path); | |
| 383 | - $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo); | |
| 384 | - $this->sendHooks(['postDelete'], [$nonExisting]); | |
| 385 | - $this->exists = false; | |
| 386 | -		} else { | |
| 387 | -			throw new NotPermittedException('No delete permission for path'); | |
| 388 | - } | |
| 389 | - } | |
| 390 | - | |
| 391 | - /** | |
| 392 | - * Add a suffix to the name in case the file exists | |
| 393 | - * | |
| 394 | - * @param string $name | |
| 395 | - * @return string | |
| 396 | - * @throws NotPermittedException | |
| 397 | - */ | |
| 398 | -	public function getNonExistingName($name) { | |
| 399 | - $uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view); | |
| 400 | - return trim($this->getRelativePath($uniqueName), '/'); | |
| 401 | - } | |
| 402 | - | |
| 403 | - /** | |
| 404 | - * @param int $limit | |
| 405 | - * @param int $offset | |
| 406 | - * @return \OCP\Files\Node[] | |
| 407 | - */ | |
| 408 | -	public function getRecent($limit, $offset = 0) { | |
| 409 | - $mimetypeLoader = \OC::$server->getMimeTypeLoader(); | |
| 410 | - $mounts = $this->root->getMountsIn($this->path); | |
| 411 | - $mounts[] = $this->getMountPoint(); | |
| 412 | - | |
| 413 | -		$mounts = array_filter($mounts, function (IMountPoint $mount) { | |
| 414 | - return $mount->getStorage(); | |
| 415 | - }); | |
| 416 | -		$storageIds = array_map(function (IMountPoint $mount) { | |
| 417 | - return $mount->getStorage()->getCache()->getNumericStorageId(); | |
| 418 | - }, $mounts); | |
| 419 | - /** @var IMountPoint[] $mountMap */ | |
| 420 | - $mountMap = array_combine($storageIds, $mounts); | |
| 421 | - $folderMimetype = $mimetypeLoader->getId(FileInfo::MIMETYPE_FOLDER); | |
| 422 | - | |
| 423 | - // Search in batches of 500 entries | |
| 424 | - $searchLimit = 500; | |
| 425 | - $results = []; | |
| 426 | - $searchResultCount = 0; | |
| 427 | - $count = 0; | |
| 428 | -		do { | |
| 429 | - $searchResult = $this->recentSearch($searchLimit, $offset, $storageIds, $folderMimetype); | |
| 430 | - | |
| 431 | - // Exit condition if there are no more results | |
| 432 | -			if (count($searchResult) === 0) { | |
| 433 | - break; | |
| 434 | - } | |
| 435 | - | |
| 436 | - $searchResultCount += count($searchResult); | |
| 437 | - | |
| 438 | - $parseResult = $this->recentParse($searchResult, $mountMap, $mimetypeLoader); | |
| 439 | - | |
| 440 | -			foreach ($parseResult as $result) { | |
| 441 | - $results[] = $result; | |
| 442 | - } | |
| 443 | - | |
| 444 | - $offset += $searchLimit; | |
| 445 | - $count++; | |
| 446 | - } while (count($results) < $limit && ($searchResultCount < (3 * $limit) || $count < 5)); | |
| 447 | - | |
| 448 | - return array_slice($results, 0, $limit); | |
| 449 | - } | |
| 450 | - | |
| 451 | -	private function recentSearch($limit, $offset, $storageIds, $folderMimetype) { | |
| 452 | - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); | |
| 453 | - $query = $builder | |
| 454 | -			->select('f.*') | |
| 455 | -			->from('filecache', 'f') | |
| 456 | -			->andWhere($builder->expr()->in('f.storage', $builder->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))) | |
| 457 | - ->andWhere($builder->expr()->orX( | |
| 458 | - // handle non empty folders separate | |
| 459 | -				$builder->expr()->neq('f.mimetype', $builder->createNamedParameter($folderMimetype, IQueryBuilder::PARAM_INT)), | |
| 460 | -				$builder->expr()->eq('f.size', new Literal(0)) | |
| 461 | - )) | |
| 462 | -			->andWhere($builder->expr()->notLike('f.path', $builder->createNamedParameter('files_versions/%'))) | |
| 463 | -			->andWhere($builder->expr()->notLike('f.path', $builder->createNamedParameter('files_trashbin/%'))) | |
| 464 | -			->orderBy('f.mtime', 'DESC') | |
| 465 | - ->setMaxResults($limit) | |
| 466 | - ->setFirstResult($offset); | |
| 467 | - return $query->execute()->fetchAll(); | |
| 468 | - } | |
| 469 | - | |
| 470 | -	private function recentParse($result, $mountMap, $mimetypeLoader) { | |
| 471 | -		$files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { | |
| 472 | - $mount = $mountMap[$entry['storage']]; | |
| 473 | - $entry['internalPath'] = $entry['path']; | |
| 474 | - $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']); | |
| 475 | - $entry['mimepart'] = $mimetypeLoader->getMimetypeById($entry['mimepart']); | |
| 476 | - $path = $this->getAbsolutePath($mount, $entry['path']); | |
| 477 | -			if (is_null($path)) { | |
| 478 | - return null; | |
| 479 | - } | |
| 480 | - $fileInfo = new \OC\Files\FileInfo($path, $mount->getStorage(), $entry['internalPath'], $entry, $mount); | |
| 481 | - return $this->root->createNode($fileInfo->getPath(), $fileInfo); | |
| 482 | - }, $result)); | |
| 483 | - | |
| 484 | -		return array_values(array_filter($files, function (Node $node) { | |
| 485 | - $cacheEntry = $node->getMountPoint()->getStorage()->getCache()->get($node->getId()); | |
| 486 | -			if (!$cacheEntry) { | |
| 487 | - return false; | |
| 488 | - } | |
| 489 | - $relative = $this->getRelativePath($node->getPath()); | |
| 490 | - return $relative !== null && $relative !== '/' | |
| 491 | - && ($cacheEntry->getPermissions() & \OCP\Constants::PERMISSION_READ) === \OCP\Constants::PERMISSION_READ; | |
| 492 | - })); | |
| 493 | - } | |
| 494 | - | |
| 495 | -	private function getAbsolutePath(IMountPoint $mount, $path) { | |
| 496 | - $storage = $mount->getStorage(); | |
| 497 | -		if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) { | |
| 498 | -			if ($storage->instanceOfStorage(SharedStorage::class)) { | |
| 499 | - $storage->getSourceStorage(); | |
| 500 | - } | |
| 501 | - /** @var \OC\Files\Storage\Wrapper\Jail $storage */ | |
| 502 | -			$jailRoot = $storage->getUnjailedPath(''); | |
| 503 | - $rootLength = strlen($jailRoot) + 1; | |
| 504 | -			if ($path === $jailRoot) { | |
| 505 | - return $mount->getMountPoint(); | |
| 506 | -			} else if (substr($path, 0, $rootLength) === $jailRoot . '/') { | |
| 507 | - return $mount->getMountPoint() . substr($path, $rootLength); | |
| 508 | -			} else { | |
| 509 | - return null; | |
| 510 | - } | |
| 511 | -		} else { | |
| 512 | - return $mount->getMountPoint() . $path; | |
| 513 | - } | |
| 514 | - } | |
| 40 | + /** | |
| 41 | + * Creates a Folder that represents a non-existing path | |
| 42 | + * | |
| 43 | + * @param string $path path | |
| 44 | + * @return string non-existing node class | |
| 45 | + */ | |
| 46 | +    protected function createNonExistingNode($path) { | |
| 47 | + return new NonExistingFolder($this->root, $this->view, $path); | |
| 48 | + } | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * @param string $path path relative to the folder | |
| 52 | + * @return string | |
| 53 | + * @throws \OCP\Files\NotPermittedException | |
| 54 | + */ | |
| 55 | +    public function getFullPath($path) { | |
| 56 | +        if (!$this->isValidPath($path)) { | |
| 57 | +            throw new NotPermittedException('Invalid path'); | |
| 58 | + } | |
| 59 | + return $this->path . $this->normalizePath($path); | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * @param string $path | |
| 64 | + * @return string | |
| 65 | + */ | |
| 66 | +    public function getRelativePath($path) { | |
| 67 | +        if ($this->path === '' or $this->path === '/') { | |
| 68 | + return $this->normalizePath($path); | |
| 69 | + } | |
| 70 | +        if ($path === $this->path) { | |
| 71 | + return '/'; | |
| 72 | +        } else if (strpos($path, $this->path . '/') !== 0) { | |
| 73 | + return null; | |
| 74 | +        } else { | |
| 75 | + $path = substr($path, strlen($this->path)); | |
| 76 | + return $this->normalizePath($path); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + | |
| 80 | + /** | |
| 81 | + * check if a node is a (grand-)child of the folder | |
| 82 | + * | |
| 83 | + * @param \OC\Files\Node\Node $node | |
| 84 | + * @return bool | |
| 85 | + */ | |
| 86 | +    public function isSubNode($node) { | |
| 87 | + return strpos($node->getPath(), $this->path . '/') === 0; | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * get the content of this directory | |
| 92 | + * | |
| 93 | + * @throws \OCP\Files\NotFoundException | |
| 94 | + * @return Node[] | |
| 95 | + */ | |
| 96 | +    public function getDirectoryListing() { | |
| 97 | + $folderContent = $this->view->getDirectoryContent($this->path); | |
| 98 | + | |
| 99 | +        return array_map(function (FileInfo $info) { | |
| 100 | +            if ($info->getMimetype() === 'httpd/unix-directory') { | |
| 101 | + return new Folder($this->root, $this->view, $info->getPath(), $info); | |
| 102 | +            } else { | |
| 103 | + return new File($this->root, $this->view, $info->getPath(), $info); | |
| 104 | + } | |
| 105 | + }, $folderContent); | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * @param string $path | |
| 110 | + * @param FileInfo $info | |
| 111 | + * @return File|Folder | |
| 112 | + */ | |
| 113 | +    protected function createNode($path, FileInfo $info = null) { | |
| 114 | +        if (is_null($info)) { | |
| 115 | + $isDir = $this->view->is_dir($path); | |
| 116 | +        } else { | |
| 117 | + $isDir = $info->getType() === FileInfo::TYPE_FOLDER; | |
| 118 | + } | |
| 119 | +        if ($isDir) { | |
| 120 | + return new Folder($this->root, $this->view, $path, $info); | |
| 121 | +        } else { | |
| 122 | + return new File($this->root, $this->view, $path, $info); | |
| 123 | + } | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * Get the node at $path | |
| 128 | + * | |
| 129 | + * @param string $path | |
| 130 | + * @return \OC\Files\Node\Node | |
| 131 | + * @throws \OCP\Files\NotFoundException | |
| 132 | + */ | |
| 133 | +    public function get($path) { | |
| 134 | + return $this->root->get($this->getFullPath($path)); | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * @param string $path | |
| 139 | + * @return bool | |
| 140 | + */ | |
| 141 | +    public function nodeExists($path) { | |
| 142 | +        try { | |
| 143 | + $this->get($path); | |
| 144 | + return true; | |
| 145 | +        } catch (NotFoundException $e) { | |
| 146 | + return false; | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 150 | + /** | |
| 151 | + * @param string $path | |
| 152 | + * @return \OC\Files\Node\Folder | |
| 153 | + * @throws \OCP\Files\NotPermittedException | |
| 154 | + */ | |
| 155 | +    public function newFolder($path) { | |
| 156 | +        if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { | |
| 157 | + $fullPath = $this->getFullPath($path); | |
| 158 | + $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); | |
| 159 | + $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]); | |
| 160 | +            if(!$this->view->mkdir($fullPath)) { | |
| 161 | +                throw new NotPermittedException('Could not create folder'); | |
| 162 | + } | |
| 163 | + $node = new Folder($this->root, $this->view, $fullPath); | |
| 164 | + $this->sendHooks(['postWrite', 'postCreate'], [$node]); | |
| 165 | + return $node; | |
| 166 | +        } else { | |
| 167 | +            throw new NotPermittedException('No create permission for folder'); | |
| 168 | + } | |
| 169 | + } | |
| 170 | + | |
| 171 | + /** | |
| 172 | + * @param string $path | |
| 173 | + * @return \OC\Files\Node\File | |
| 174 | + * @throws \OCP\Files\NotPermittedException | |
| 175 | + */ | |
| 176 | +    public function newFile($path) { | |
| 177 | +        if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { | |
| 178 | + $fullPath = $this->getFullPath($path); | |
| 179 | + $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); | |
| 180 | + $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]); | |
| 181 | +            if (!$this->view->touch($fullPath)) { | |
| 182 | +                throw new NotPermittedException('Could not create path'); | |
| 183 | + } | |
| 184 | + $node = new File($this->root, $this->view, $fullPath); | |
| 185 | + $this->sendHooks(['postWrite', 'postCreate'], [$node]); | |
| 186 | + return $node; | |
| 187 | + } | |
| 188 | +        throw new NotPermittedException('No create permission for path'); | |
| 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 = ltrim(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 | +            if ($user === $this->getAppDataDirectoryName()) { | |
| 303 | + return $this->getByIdInRootMount((int) $id); | |
| 304 | + } | |
| 305 | + return []; | |
| 306 | + } | |
| 307 | + | |
| 308 | +        $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($folderMounts, $id) { | |
| 309 | + $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; | |
| 310 | + $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); | |
| 311 | +            if (!$cacheEntry) { | |
| 312 | + return null; | |
| 313 | + } | |
| 314 | + | |
| 315 | + // cache jails will hide the "true" internal path | |
| 316 | + $internalPath = ltrim($cachedMountInfo->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); | |
| 317 | + $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); | |
| 318 | + $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); | |
| 319 | + $absolutePath = rtrim($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 | + $nodes = array_filter($nodes); | |
| 327 | + | |
| 328 | +        return array_filter($nodes, function (Node $node) { | |
| 329 | + return $this->getRelativePath($node->getPath()); | |
| 330 | + }); | |
| 331 | + } | |
| 332 | + | |
| 333 | +    protected function getAppDataDirectoryName(): string { | |
| 334 | +        $instanceId = \OC::$server->getConfig()->getSystemValueString('instanceid'); | |
| 335 | + return 'appdata_' . $instanceId; | |
| 336 | + } | |
| 337 | + | |
| 338 | + /** | |
| 339 | + * In case the path we are currently in is inside the appdata_* folder, | |
| 340 | + * the original getById method does not work, because it can only look inside | |
| 341 | + * the user's mount points. But the user has no mount point for the root storage. | |
| 342 | + * | |
| 343 | + * So in that case we directly check the mount of the root if it contains | |
| 344 | + * the id. If it does we check if the path is inside the path we are working | |
| 345 | + * in. | |
| 346 | + * | |
| 347 | + * @param int $id | |
| 348 | + * @return array | |
| 349 | + */ | |
| 350 | +    protected function getByIdInRootMount(int $id): array { | |
| 351 | +        $mount = $this->root->getMount(''); | |
| 352 | + $cacheEntry = $mount->getStorage()->getCache($this->path)->get($id); | |
| 353 | +        if (!$cacheEntry) { | |
| 354 | + return []; | |
| 355 | + } | |
| 356 | + | |
| 357 | + $absolutePath = '/' . ltrim($cacheEntry->getPath(), '/'); | |
| 358 | + $currentPath = rtrim($this->path, '/') . '/'; | |
| 359 | + | |
| 360 | +        if (strpos($absolutePath, $currentPath) !== 0) { | |
| 361 | + return []; | |
| 362 | + } | |
| 363 | + | |
| 364 | + return [$this->root->createNode( | |
| 365 | + $absolutePath, new \OC\Files\FileInfo( | |
| 366 | + $absolutePath, | |
| 367 | + $mount->getStorage(), | |
| 368 | + $cacheEntry->getPath(), | |
| 369 | + $cacheEntry, | |
| 370 | + $mount | |
| 371 | + ))]; | |
| 372 | + } | |
| 373 | + | |
| 374 | +    public function getFreeSpace() { | |
| 375 | + return $this->view->free_space($this->path); | |
| 376 | + } | |
| 377 | + | |
| 378 | +    public function delete() { | |
| 379 | +        if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { | |
| 380 | +            $this->sendHooks(array('preDelete')); | |
| 381 | + $fileInfo = $this->getFileInfo(); | |
| 382 | + $this->view->rmdir($this->path); | |
| 383 | + $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo); | |
| 384 | + $this->sendHooks(['postDelete'], [$nonExisting]); | |
| 385 | + $this->exists = false; | |
| 386 | +        } else { | |
| 387 | +            throw new NotPermittedException('No delete permission for path'); | |
| 388 | + } | |
| 389 | + } | |
| 390 | + | |
| 391 | + /** | |
| 392 | + * Add a suffix to the name in case the file exists | |
| 393 | + * | |
| 394 | + * @param string $name | |
| 395 | + * @return string | |
| 396 | + * @throws NotPermittedException | |
| 397 | + */ | |
| 398 | +    public function getNonExistingName($name) { | |
| 399 | + $uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view); | |
| 400 | + return trim($this->getRelativePath($uniqueName), '/'); | |
| 401 | + } | |
| 402 | + | |
| 403 | + /** | |
| 404 | + * @param int $limit | |
| 405 | + * @param int $offset | |
| 406 | + * @return \OCP\Files\Node[] | |
| 407 | + */ | |
| 408 | +    public function getRecent($limit, $offset = 0) { | |
| 409 | + $mimetypeLoader = \OC::$server->getMimeTypeLoader(); | |
| 410 | + $mounts = $this->root->getMountsIn($this->path); | |
| 411 | + $mounts[] = $this->getMountPoint(); | |
| 412 | + | |
| 413 | +        $mounts = array_filter($mounts, function (IMountPoint $mount) { | |
| 414 | + return $mount->getStorage(); | |
| 415 | + }); | |
| 416 | +        $storageIds = array_map(function (IMountPoint $mount) { | |
| 417 | + return $mount->getStorage()->getCache()->getNumericStorageId(); | |
| 418 | + }, $mounts); | |
| 419 | + /** @var IMountPoint[] $mountMap */ | |
| 420 | + $mountMap = array_combine($storageIds, $mounts); | |
| 421 | + $folderMimetype = $mimetypeLoader->getId(FileInfo::MIMETYPE_FOLDER); | |
| 422 | + | |
| 423 | + // Search in batches of 500 entries | |
| 424 | + $searchLimit = 500; | |
| 425 | + $results = []; | |
| 426 | + $searchResultCount = 0; | |
| 427 | + $count = 0; | |
| 428 | +        do { | |
| 429 | + $searchResult = $this->recentSearch($searchLimit, $offset, $storageIds, $folderMimetype); | |
| 430 | + | |
| 431 | + // Exit condition if there are no more results | |
| 432 | +            if (count($searchResult) === 0) { | |
| 433 | + break; | |
| 434 | + } | |
| 435 | + | |
| 436 | + $searchResultCount += count($searchResult); | |
| 437 | + | |
| 438 | + $parseResult = $this->recentParse($searchResult, $mountMap, $mimetypeLoader); | |
| 439 | + | |
| 440 | +            foreach ($parseResult as $result) { | |
| 441 | + $results[] = $result; | |
| 442 | + } | |
| 443 | + | |
| 444 | + $offset += $searchLimit; | |
| 445 | + $count++; | |
| 446 | + } while (count($results) < $limit && ($searchResultCount < (3 * $limit) || $count < 5)); | |
| 447 | + | |
| 448 | + return array_slice($results, 0, $limit); | |
| 449 | + } | |
| 450 | + | |
| 451 | +    private function recentSearch($limit, $offset, $storageIds, $folderMimetype) { | |
| 452 | + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); | |
| 453 | + $query = $builder | |
| 454 | +            ->select('f.*') | |
| 455 | +            ->from('filecache', 'f') | |
| 456 | +            ->andWhere($builder->expr()->in('f.storage', $builder->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))) | |
| 457 | + ->andWhere($builder->expr()->orX( | |
| 458 | + // handle non empty folders separate | |
| 459 | +                $builder->expr()->neq('f.mimetype', $builder->createNamedParameter($folderMimetype, IQueryBuilder::PARAM_INT)), | |
| 460 | +                $builder->expr()->eq('f.size', new Literal(0)) | |
| 461 | + )) | |
| 462 | +            ->andWhere($builder->expr()->notLike('f.path', $builder->createNamedParameter('files_versions/%'))) | |
| 463 | +            ->andWhere($builder->expr()->notLike('f.path', $builder->createNamedParameter('files_trashbin/%'))) | |
| 464 | +            ->orderBy('f.mtime', 'DESC') | |
| 465 | + ->setMaxResults($limit) | |
| 466 | + ->setFirstResult($offset); | |
| 467 | + return $query->execute()->fetchAll(); | |
| 468 | + } | |
| 469 | + | |
| 470 | +    private function recentParse($result, $mountMap, $mimetypeLoader) { | |
| 471 | +        $files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { | |
| 472 | + $mount = $mountMap[$entry['storage']]; | |
| 473 | + $entry['internalPath'] = $entry['path']; | |
| 474 | + $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']); | |
| 475 | + $entry['mimepart'] = $mimetypeLoader->getMimetypeById($entry['mimepart']); | |
| 476 | + $path = $this->getAbsolutePath($mount, $entry['path']); | |
| 477 | +            if (is_null($path)) { | |
| 478 | + return null; | |
| 479 | + } | |
| 480 | + $fileInfo = new \OC\Files\FileInfo($path, $mount->getStorage(), $entry['internalPath'], $entry, $mount); | |
| 481 | + return $this->root->createNode($fileInfo->getPath(), $fileInfo); | |
| 482 | + }, $result)); | |
| 483 | + | |
| 484 | +        return array_values(array_filter($files, function (Node $node) { | |
| 485 | + $cacheEntry = $node->getMountPoint()->getStorage()->getCache()->get($node->getId()); | |
| 486 | +            if (!$cacheEntry) { | |
| 487 | + return false; | |
| 488 | + } | |
| 489 | + $relative = $this->getRelativePath($node->getPath()); | |
| 490 | + return $relative !== null && $relative !== '/' | |
| 491 | + && ($cacheEntry->getPermissions() & \OCP\Constants::PERMISSION_READ) === \OCP\Constants::PERMISSION_READ; | |
| 492 | + })); | |
| 493 | + } | |
| 494 | + | |
| 495 | +    private function getAbsolutePath(IMountPoint $mount, $path) { | |
| 496 | + $storage = $mount->getStorage(); | |
| 497 | +        if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) { | |
| 498 | +            if ($storage->instanceOfStorage(SharedStorage::class)) { | |
| 499 | + $storage->getSourceStorage(); | |
| 500 | + } | |
| 501 | + /** @var \OC\Files\Storage\Wrapper\Jail $storage */ | |
| 502 | +            $jailRoot = $storage->getUnjailedPath(''); | |
| 503 | + $rootLength = strlen($jailRoot) + 1; | |
| 504 | +            if ($path === $jailRoot) { | |
| 505 | + return $mount->getMountPoint(); | |
| 506 | +            } else if (substr($path, 0, $rootLength) === $jailRoot . '/') { | |
| 507 | + return $mount->getMountPoint() . substr($path, $rootLength); | |
| 508 | +            } else { | |
| 509 | + return null; | |
| 510 | + } | |
| 511 | +        } else { | |
| 512 | + return $mount->getMountPoint() . $path; | |
| 513 | + } | |
| 514 | + } | |
| 515 | 515 | } | 
| @@ -56,7 +56,7 @@ discard block | ||
| 56 | 56 |  		if (!$this->isValidPath($path)) { | 
| 57 | 57 |  			throw new NotPermittedException('Invalid path'); | 
| 58 | 58 | } | 
| 59 | - return $this->path . $this->normalizePath($path); | |
| 59 | + return $this->path.$this->normalizePath($path); | |
| 60 | 60 | } | 
| 61 | 61 | |
| 62 | 62 | /** | 
| @@ -69,7 +69,7 @@ discard block | ||
| 69 | 69 | } | 
| 70 | 70 |  		if ($path === $this->path) { | 
| 71 | 71 | return '/'; | 
| 72 | -		} else if (strpos($path, $this->path . '/') !== 0) { | |
| 72 | +		} else if (strpos($path, $this->path.'/') !== 0) { | |
| 73 | 73 | return null; | 
| 74 | 74 |  		} else { | 
| 75 | 75 | $path = substr($path, strlen($this->path)); | 
| @@ -84,7 +84,7 @@ discard block | ||
| 84 | 84 | * @return bool | 
| 85 | 85 | */ | 
| 86 | 86 |  	public function isSubNode($node) { | 
| 87 | - return strpos($node->getPath(), $this->path . '/') === 0; | |
| 87 | + return strpos($node->getPath(), $this->path.'/') === 0; | |
| 88 | 88 | } | 
| 89 | 89 | |
| 90 | 90 | /** | 
| @@ -96,7 +96,7 @@ discard block | ||
| 96 | 96 |  	public function getDirectoryListing() { | 
| 97 | 97 | $folderContent = $this->view->getDirectoryContent($this->path); | 
| 98 | 98 | |
| 99 | -		return array_map(function (FileInfo $info) { | |
| 99 | +		return array_map(function(FileInfo $info) { | |
| 100 | 100 |  			if ($info->getMimetype() === 'httpd/unix-directory') { | 
| 101 | 101 | return new Folder($this->root, $this->view, $info->getPath(), $info); | 
| 102 | 102 |  			} else { | 
| @@ -157,7 +157,7 @@ discard block | ||
| 157 | 157 | $fullPath = $this->getFullPath($path); | 
| 158 | 158 | $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); | 
| 159 | 159 | $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]); | 
| 160 | -			if(!$this->view->mkdir($fullPath)) { | |
| 160 | +			if (!$this->view->mkdir($fullPath)) { | |
| 161 | 161 |  				throw new NotPermittedException('Could not create folder'); | 
| 162 | 162 | } | 
| 163 | 163 | $node = new Folder($this->root, $this->view, $fullPath); | 
| @@ -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,18 +305,18 @@ discard block | ||
| 305 | 305 | return []; | 
| 306 | 306 | } | 
| 307 | 307 | |
| 308 | -		$nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($folderMounts, $id) { | |
| 308 | +		$nodes = array_map(function(ICachedMountInfo $cachedMountInfo) use ($folderMounts, $id) { | |
| 309 | 309 | $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; | 
| 310 | - $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); | |
| 310 | + $cacheEntry = $mount->getStorage()->getCache()->get((int) $id); | |
| 311 | 311 |  			if (!$cacheEntry) { | 
| 312 | 312 | return null; | 
| 313 | 313 | } | 
| 314 | 314 | |
| 315 | 315 | // cache jails will hide the "true" internal path | 
| 316 | - $internalPath = ltrim($cachedMountInfo->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); | |
| 316 | + $internalPath = ltrim($cachedMountInfo->getRootInternalPath().'/'.$cacheEntry->getPath(), '/'); | |
| 317 | 317 | $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); | 
| 318 | 318 | $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); | 
| 319 | - $absolutePath = rtrim($cachedMountInfo->getMountPoint() . $pathRelativeToMount, '/'); | |
| 319 | + $absolutePath = rtrim($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)) | 
| @@ -325,14 +325,14 @@ discard block | ||
| 325 | 325 | |
| 326 | 326 | $nodes = array_filter($nodes); | 
| 327 | 327 | |
| 328 | -		return array_filter($nodes, function (Node $node) { | |
| 328 | +		return array_filter($nodes, function(Node $node) { | |
| 329 | 329 | return $this->getRelativePath($node->getPath()); | 
| 330 | 330 | }); | 
| 331 | 331 | } | 
| 332 | 332 | |
| 333 | 333 |  	protected function getAppDataDirectoryName(): string { | 
| 334 | 334 |  		$instanceId = \OC::$server->getConfig()->getSystemValueString('instanceid'); | 
| 335 | - return 'appdata_' . $instanceId; | |
| 335 | + return 'appdata_'.$instanceId; | |
| 336 | 336 | } | 
| 337 | 337 | |
| 338 | 338 | /** | 
| @@ -354,8 +354,8 @@ discard block | ||
| 354 | 354 | return []; | 
| 355 | 355 | } | 
| 356 | 356 | |
| 357 | - $absolutePath = '/' . ltrim($cacheEntry->getPath(), '/'); | |
| 358 | - $currentPath = rtrim($this->path, '/') . '/'; | |
| 357 | + $absolutePath = '/'.ltrim($cacheEntry->getPath(), '/'); | |
| 358 | + $currentPath = rtrim($this->path, '/').'/'; | |
| 359 | 359 | |
| 360 | 360 |  		if (strpos($absolutePath, $currentPath) !== 0) { | 
| 361 | 361 | return []; | 
| @@ -410,10 +410,10 @@ discard block | ||
| 410 | 410 | $mounts = $this->root->getMountsIn($this->path); | 
| 411 | 411 | $mounts[] = $this->getMountPoint(); | 
| 412 | 412 | |
| 413 | -		$mounts = array_filter($mounts, function (IMountPoint $mount) { | |
| 413 | +		$mounts = array_filter($mounts, function(IMountPoint $mount) { | |
| 414 | 414 | return $mount->getStorage(); | 
| 415 | 415 | }); | 
| 416 | -		$storageIds = array_map(function (IMountPoint $mount) { | |
| 416 | +		$storageIds = array_map(function(IMountPoint $mount) { | |
| 417 | 417 | return $mount->getStorage()->getCache()->getNumericStorageId(); | 
| 418 | 418 | }, $mounts); | 
| 419 | 419 | /** @var IMountPoint[] $mountMap */ | 
| @@ -468,7 +468,7 @@ discard block | ||
| 468 | 468 | } | 
| 469 | 469 | |
| 470 | 470 |  	private function recentParse($result, $mountMap, $mimetypeLoader) { | 
| 471 | -		$files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { | |
| 471 | +		$files = array_filter(array_map(function(array $entry) use ($mountMap, $mimetypeLoader) { | |
| 472 | 472 | $mount = $mountMap[$entry['storage']]; | 
| 473 | 473 | $entry['internalPath'] = $entry['path']; | 
| 474 | 474 | $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']); | 
| @@ -481,7 +481,7 @@ discard block | ||
| 481 | 481 | return $this->root->createNode($fileInfo->getPath(), $fileInfo); | 
| 482 | 482 | }, $result)); | 
| 483 | 483 | |
| 484 | -		return array_values(array_filter($files, function (Node $node) { | |
| 484 | +		return array_values(array_filter($files, function(Node $node) { | |
| 485 | 485 | $cacheEntry = $node->getMountPoint()->getStorage()->getCache()->get($node->getId()); | 
| 486 | 486 |  			if (!$cacheEntry) { | 
| 487 | 487 | return false; | 
| @@ -503,13 +503,13 @@ discard block | ||
| 503 | 503 | $rootLength = strlen($jailRoot) + 1; | 
| 504 | 504 |  			if ($path === $jailRoot) { | 
| 505 | 505 | return $mount->getMountPoint(); | 
| 506 | -			} else if (substr($path, 0, $rootLength) === $jailRoot . '/') { | |
| 507 | - return $mount->getMountPoint() . substr($path, $rootLength); | |
| 506 | +			} else if (substr($path, 0, $rootLength) === $jailRoot.'/') { | |
| 507 | + return $mount->getMountPoint().substr($path, $rootLength); | |
| 508 | 508 |  			} else { | 
| 509 | 509 | return null; | 
| 510 | 510 | } | 
| 511 | 511 |  		} else { | 
| 512 | - return $mount->getMountPoint() . $path; | |
| 512 | + return $mount->getMountPoint().$path; | |
| 513 | 513 | } | 
| 514 | 514 | } | 
| 515 | 515 | } |