From 13c01e62cf9cd1d241b447b80fda719fb2df9931 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 22 Apr 2016 11:17:36 +0200 Subject: [PATCH] Mark $usersSetup only if user was found in initMountPoints initMountPoints is marking a user as successfully initialized too early. If the user was not found an NoUserException was thrown, the second time initMountPoints is called would not rethrow the exception and happily continue. This fix makes sure that we consistently throw NoUserException when initMountPoints is called repeatedly with invalid users. --- lib/private/files/filesystem.php | 4 ++-- tests/lib/files/filesystem.php | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php index ec9b537a35..7283c815c9 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -378,8 +378,6 @@ class Filesystem { if (isset(self::$usersSetup[$user])) { return; } - self::$usersSetup[$user] = true; - $root = \OC_User::getHome($user); $userManager = \OC::$server->getUserManager(); @@ -390,6 +388,8 @@ class Filesystem { throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); } + self::$usersSetup[$user] = true; + $homeStorage = \OC::$server->getConfig()->getSystemValue('objectstore'); if (!empty($homeStorage)) { // sanity checks diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php index 8245af0ace..b5a3e14725 100644 --- a/tests/lib/files/filesystem.php +++ b/tests/lib/files/filesystem.php @@ -341,6 +341,28 @@ class Filesystem extends \Test\TestCase { $this->assertEquals(2, $thrown); } + /** + * Tests that an exception is thrown when passed user does not exist. + */ + public function testLocalMountWhenUserDoesNotExistTwice() { + $thrown = 0; + $userId = $this->getUniqueID('user_'); + + try { + \OC\Files\Filesystem::initMountPoints($userId); + } catch (NoUserException $e) { + $thrown++; + } + + try { + \OC\Files\Filesystem::initMountPoints($userId); + } catch (NoUserException $e) { + $thrown++; + } + + $this->assertEquals(2, $thrown); + } + /** * Tests that the home storage is used for the user's mount point */