diff options
Diffstat (limited to 'lib/private/Files')
-rw-r--r-- | lib/private/Files/Config/UserMountCache.php | 12 | ||||
-rw-r--r-- | lib/private/Files/Node/Folder.php | 7 | ||||
-rw-r--r-- | lib/private/Files/Utils/Scanner.php | 5 |
3 files changed, 20 insertions, 4 deletions
diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 423eb5c423d..5cbdfaa9d82 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -220,15 +220,20 @@ class UserMountCache implements IUserMountCache { /** * @param int $numericStorageId + * @param string|null $user limit the results to a single user * @return CachedMountInfo[] */ - public function getMountsForStorageId($numericStorageId) { + public function getMountsForStorageId($numericStorageId, $user = null) { $builder = $this->connection->getQueryBuilder(); $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') ->from('mounts', 'm') ->innerJoin('m', 'filecache', 'f' , $builder->expr()->eq('m.root_id', 'f.fileid')) ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); + if ($user) { + $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); + } + $rows = $query->execute()->fetchAll(); return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); @@ -278,16 +283,17 @@ class UserMountCache implements IUserMountCache { /** * @param int $fileId + * @param string|null $user optionally restrict the results to a single user * @return ICachedMountInfo[] * @since 9.0.0 */ - public function getMountsForFileId($fileId) { + public function getMountsForFileId($fileId, $user = null) { try { list($storageId, $internalPath) = $this->getCacheInfoFromFileId($fileId); } catch (NotFoundException $e) { return []; } - $mountsForStorage = $this->getMountsForStorageId($storageId); + $mountsForStorage = $this->getMountsForStorageId($storageId, $user); // filter mounts that are from the same storage but a different directory return array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) { diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index 9809c6b7d11..fcadbe27393 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -280,7 +280,12 @@ class Folder extends Node implements \OCP\Files\Folder { */ public function getById($id) { $mountCache = $this->root->getUserMountCache(); - $mountsContainingFile = $mountCache->getMountsForFileId((int)$id); + if (strpos($this->getPath(), '/', 1) > 0) { + list(, $user) = explode('/', $this->getPath()); + } else { + $user = null; + } + $mountsContainingFile = $mountCache->getMountsForFileId((int)$id, $user); $mounts = $this->root->getMountsIn($this->path); $mounts[] = $this->root->getMount($this->path); /** @var IMountPoint[] $folderMounts */ diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php index e76f3225c3c..02f355fd4d9 100644 --- a/lib/private/Files/Utils/Scanner.php +++ b/lib/private/Files/Utils/Scanner.php @@ -32,6 +32,7 @@ use OC\ForbiddenException; use OC\Hooks\PublicEmitter; use OC\Lock\DBLockingProvider; use OCA\Files_Sharing\SharedStorage; +use OCP\Files\NotFoundException; use OCP\Files\Storage\IStorage; use OCP\Files\StorageNotAvailableException; use OCP\ILogger; @@ -161,6 +162,7 @@ class Scanner extends PublicEmitter { /** * @param string $dir * @throws \OC\ForbiddenException + * @throws \OCP\Files\NotFoundException */ public function scan($dir = '') { if (!Filesystem::isValidPath($dir)) { @@ -210,6 +212,9 @@ class Scanner extends PublicEmitter { $this->triggerPropagator($storage, $path); }); + if (!$storage->file_exists($relativePath)) { + throw new NotFoundException($dir); + } if (!$isDbLocking) { $this->db->beginTransaction(); } |