aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2017-04-21 19:43:53 +0200
committerGitHub <noreply@github.com>2017-04-21 19:43:53 +0200
commitd46b155916c4c49fffb5bf8c4391331ce90b44c1 (patch)
tree1069317f58f3ee65b7ba5d9479793bb42c9e5c40 /lib
parent1666a17ebe93cda3274b5754b4337b1d49b02ad2 (diff)
parent6fbe991afbb5df36c2fef5cac8c9681f91aed311 (diff)
downloadnextcloud-server-d46b155916c4c49fffb5bf8c4391331ce90b44c1.tar.gz
nextcloud-server-d46b155916c4c49fffb5bf8c4391331ce90b44c1.zip
Merge pull request #4428 from nextcloud/file-by-id-limit-user
limit the user when searching for a file by id if we know the user already
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Config/UserMountCache.php12
-rw-r--r--lib/private/Files/Node/Folder.php7
-rw-r--r--lib/public/Files/Config/IUserMountCache.php6
3 files changed, 19 insertions, 6 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/public/Files/Config/IUserMountCache.php b/lib/public/Files/Config/IUserMountCache.php
index c141d019c2f..cf30d8fb431 100644
--- a/lib/public/Files/Config/IUserMountCache.php
+++ b/lib/public/Files/Config/IUserMountCache.php
@@ -53,10 +53,11 @@ interface IUserMountCache {
* Get all cached mounts by storage
*
* @param int $numericStorageId
+ * @param string|null $user limit the results to a single user @since 12.0.0
* @return ICachedMountInfo[]
* @since 9.0.0
*/
- public function getMountsForStorageId($numericStorageId);
+ public function getMountsForStorageId($numericStorageId, $user = null);
/**
* Get all cached mounts by root
@@ -71,10 +72,11 @@ interface IUserMountCache {
* Get all cached mounts that contain a file
*
* @param int $fileId
+ * @param string|null $user optionally restrict the results to a single user @since 12.0.0
* @return ICachedMountInfo[]
* @since 9.0.0
*/
- public function getMountsForFileId($fileId);
+ public function getMountsForFileId($fileId, $user = null);
/**
* Remove all cached mounts for a user