From 5a74b9cb999d6563b6b6f97cd3232bebe2ec3e57 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 19 Mar 2018 22:05:04 +0100 Subject: [PATCH 1/2] Fix proper permissions for multiple file access Fixes #8890 In case you have access to a file via multiple ways, for example: 1. the file is shared with you with permission read only 2. the folder containing the file is shared with your read/write Requesting the getById function on the userFolder would give back two entries but both with the same permissions. Depending on the node you picked this is not right. Signed-off-by: Roeland Jago Douma --- lib/private/Files/Node/Folder.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index fcadbe27393ac..95ceeee369843 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -302,18 +302,15 @@ public function getById($id) { return []; } - // we only need to get the cache info once, since all mounts we found point to the same storage - - $mount = $folderMounts[$mountsContainingFile[0]->getMountPoint()]; - $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); - if (!$cacheEntry) { - return []; - } - // cache jails will hide the "true" internal path - $internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); - - $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) { + $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($folderMounts, $id) { $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; + $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); + if (!$cacheEntry) { + return null; + } + + // cache jails will hide the "true" internal path + $internalPath = ltrim($cachedMountInfo->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); $absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount; @@ -323,6 +320,8 @@ public function getById($id) { )); }, $mountsContainingFile); + $nodes = array_filter($nodes); + return array_filter($nodes, function (Node $node) { return $this->getRelativePath($node->getPath()); }); From af317a1e38243fc7fe01aeb4466cd9b9ecbc5744 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 22 Mar 2018 12:06:45 +0100 Subject: [PATCH 2/2] Fix test Signed-off-by: Roeland Jago Douma --- tests/lib/Files/Node/FolderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 6479dad58d330..c924c090232b5 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -682,7 +682,7 @@ public function testGetByIdMultipleStorages() { $fileInfo = new CacheEntry(['path' => 'foo/qwerty', 'mimetype' => 'text/plain'], null); - $storage->expects($this->once()) + $storage->expects($this->exactly(2)) ->method('getCache') ->will($this->returnValue($cache));