From b884c25950e2ad3f0b01dfc63cd9bbfa07d90d7a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 24 Nov 2016 11:44:18 +0100 Subject: [PATCH] filter out oc_mounts results from non existing users Signed-off-by: Robin Appelman --- lib/private/Files/Config/UserMountCache.php | 9 ++++++--- tests/lib/Files/Config/UserMountCacheTest.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index bd8343fa440..6feb3085e9e 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -187,6 +187,9 @@ class UserMountCache implements IUserMountCache { private function dbRowToMountInfo(array $row) { $user = $this->userManager->get($row['user_id']); + if (is_null($user)) { + return null; + } return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $row['mount_id']); } @@ -203,7 +206,7 @@ class UserMountCache implements IUserMountCache { $rows = $query->execute()->fetchAll(); - $this->mountsForUsers[$user->getUID()] = array_map([$this, 'dbRowToMountInfo'], $rows); + $this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); } return $this->mountsForUsers[$user->getUID()]; } @@ -220,7 +223,7 @@ class UserMountCache implements IUserMountCache { $rows = $query->execute()->fetchAll(); - return array_map([$this, 'dbRowToMountInfo'], $rows); + return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); } /** @@ -235,7 +238,7 @@ class UserMountCache implements IUserMountCache { $rows = $query->execute()->fetchAll(); - return array_map([$this, 'dbRowToMountInfo'], $rows); + return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); } /** diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index 8e569c50e09..0fd9213e9a0 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -410,7 +410,7 @@ class UserMountCacheTest extends TestCase { public function testGetMountsForFileIdDeletedUser() { $user1 = $this->userManager->get('u1'); - list($storage1, $rootId) = $this->getStorage(2); + $storage1 = $this->getStorage(1, 2); $rootId = $this->createCacheEntry('', 2); $mount1 = new MountPoint($storage1, '/foo/'); $this->cache->registerMounts($user1, [$mount1]);