From b069f33a72fde9ef0f0d502ca2e1c78f777155c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 2 Apr 2015 11:05:14 +0200 Subject: [PATCH] throw exception when backends don't provide a user instead of creating legacy local storages --- lib/private/files/filesystem.php | 66 ++++++++++++++-------------- lib/private/user/nouserexception.php | 14 ++++++ 2 files changed, 47 insertions(+), 33 deletions(-) create mode 100644 lib/private/user/nouserexception.php diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php index 95e630b776..10c64e1301 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -373,41 +373,41 @@ class Filesystem { $userObject = \OC_User::getManager()->get($user); - if (!is_null($userObject)) { - $homeStorage = \OC_Config::getValue( 'objectstore' ); - if (!empty($homeStorage)) { - // sanity checks - if (empty($homeStorage['class'])) { - \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); - } - if (!isset($homeStorage['arguments'])) { - $homeStorage['arguments'] = array(); - } - // instantiate object store implementation - $homeStorage['arguments']['objectstore'] = new $homeStorage['class']($homeStorage['arguments']); - // mount with home object store implementation - $homeStorage['class'] = '\OC\Files\ObjectStore\HomeObjectStoreStorage'; - } else { - $homeStorage = array( - //default home storage configuration: - 'class' => '\OC\Files\Storage\Home', - 'arguments' => array() - ); - } - $homeStorage['arguments']['user'] = $userObject; - - // check for legacy home id (<= 5.0.12) - if (\OC\Files\Cache\Storage::exists('local::' . $root . '/')) { - $homeStorage['arguments']['legacy'] = true; - } - - self::mount($homeStorage['class'], $homeStorage['arguments'], $user); - - $home = \OC\Files\Filesystem::getStorage($user); + if (is_null($userObject)) { + \OCP\Util::writeLog('files', ' Backends provided no user object for '.$user, \OCP\Util::ERROR); + throw new \OC\User\NoUserException(); } - else { - self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user); + + $homeStorage = \OC_Config::getValue( 'objectstore' ); + if (!empty($homeStorage)) { + // sanity checks + if (empty($homeStorage['class'])) { + \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); + } + if (!isset($homeStorage['arguments'])) { + $homeStorage['arguments'] = array(); + } + // instantiate object store implementation + $homeStorage['arguments']['objectstore'] = new $homeStorage['class']($homeStorage['arguments']); + // mount with home object store implementation + $homeStorage['class'] = '\OC\Files\ObjectStore\HomeObjectStoreStorage'; + } else { + $homeStorage = array( + //default home storage configuration: + 'class' => '\OC\Files\Storage\Home', + 'arguments' => array() + ); } + $homeStorage['arguments']['user'] = $userObject; + + // check for legacy home id (<= 5.0.12) + if (\OC\Files\Cache\Storage::exists('local::' . $root . '/')) { + $homeStorage['arguments']['legacy'] = true; + } + + self::mount($homeStorage['class'], $homeStorage['arguments'], $user); + + $home = \OC\Files\Filesystem::getStorage($user); self::mountCacheDir($user); diff --git a/lib/private/user/nouserexception.php b/lib/private/user/nouserexception.php new file mode 100644 index 0000000000..9452362b4e --- /dev/null +++ b/lib/private/user/nouserexception.php @@ -0,0 +1,14 @@ + + * @copyright Jörn Friedrich Dreyer 2015 + */ + +namespace OC\User; + +class NoUserException extends \Exception {} \ No newline at end of file