From 0b263adfe7edbfcbf6cde36e4b33496d7d91fd59 Mon Sep 17 00:00:00 2001 From: Gandolf90 Date: Wed, 25 Oct 2017 19:09:53 +0200 Subject: [PATCH] #27854 non existing folder skeletondirectory added new test throw Exception on false config catch Exception and write error to Log --- lib/private/User/Session.php | 5 ++++- lib/private/legacy/util.php | 13 +++++++++---- tests/lib/UtilTest.php | 13 +++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index 2a429b0b697b..eb5edf3d5aea 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -418,6 +418,9 @@ public function prepareUserLogin($firstTimeLogin = false) { \OC::$server->getLogger()->warning( 'Skeleton not created due to missing write permission' ); + } catch(\OC\HintException $hintEx) { + // only if Skeleton no existing Dir + \OC::$server->getLogger()->error($hintEx->getMessage()); } // trigger any other initialization @@ -842,7 +845,7 @@ public function logout() { try { $this->tokenProvider->invalidateToken($this->session->getId()); } catch (SessionNotAvailableException $ex) { - + } } $this->setUser(null); diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index 303066055930..f1ed5a1ccf66 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -388,11 +388,16 @@ public static function getUserQuota($userId) { * * @param String $userId * @param \OCP\Files\Folder $userDirectory + * @throws \OC\HintException */ public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { $skeletonDirectory = \OCP\Config::getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); + if (!is_dir($skeletonDirectory)) { + throw new \OC\HintException('The skeleton folder '.$skeletonDirectory.' is not accessible'); + } + if (!empty($skeletonDirectory)) { \OCP\Util::writeLog( 'files_skeleton', @@ -458,8 +463,8 @@ public static function getVersionString() { } /** - * @description get the current installed edition of ownCloud. - * There is the community edition that returns "Community" and + * @description get the current installed edition of ownCloud. + * There is the community edition that returns "Community" and * the enterprise edition that returns "Enterprise". * @return string */ @@ -569,7 +574,7 @@ public static function addVendorScript($application, $file = null, $prepend = fa * * @param string $application application id * @param string $languageCode language code, defaults to the current language - * @param bool $prepend prepend the Script to the beginning of the list + * @param bool $prepend prepend the Script to the beginning of the list */ public static function addTranslations($application, $languageCode = null, $prepend = false) { if (is_null($languageCode)) { @@ -614,7 +619,7 @@ public static function addVendorStyle($application, $file = null, $prepend = fal * * @param string $application application id * @param bool $prepend prepend the file to the beginning of the list - * @param string $path + * @param string $path * @param string $type (script or style) * @return void */ diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php index 442ece6dcce4..7cb0360b15e3 100644 --- a/tests/lib/UtilTest.php +++ b/tests/lib/UtilTest.php @@ -413,6 +413,19 @@ public function testCheckDataDirectoryValidity() { $this->assertNotEmpty($errors); } + /** + * @expectedException \OC\HintException + * @expectedExceptionMessage The skeleton folder /not/existing/Directory is not accessible + */ + public function testCopySkeletonDirectory() { + $config = \OC::$server->getConfig(); + $config->setSystemValue('skeletondirectory', '/not/existing/Directory'); + $userFolder = $this->createMock('\OCP\Files\Folder'); + \OC_Util::copySkeleton($config, $userFolder); + + $config->deleteSystemValue('skeletondirectory'); + } + protected function setUp() { parent::setUp();