From: Bjoern Schiessle Date: Thu, 26 Mar 2015 20:56:44 +0000 (+0100) Subject: always fall back to default share folder X-Git-Tag: v7.0.6RC1~14^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0cdeeec82b66495f6070b84c1039ebd29150b704;p=nextcloud-server.git always fall back to default share folder --- diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php index f444404c2b1..1b03fd24d54 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -243,9 +243,21 @@ class Helper { * @return string */ public static function getShareFolder() { - $shareFolder = \OCP\Config::getSystemValue('share_folder', '/'); + $shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/'); + $shareFolder = \OC\Files\Filesystem::normalizePath($shareFolder); + + if (!\OC\Files\Filesystem::file_exists($shareFolder)) { + $dir = ''; + $subdirs = explode('/', $shareFolder); + foreach ($subdirs as $subdir) { + $dir = $dir . '/' . $subdir; + if (!\OC\Files\Filesystem::is_dir($dir)) { + \OC\Files\Filesystem::mkdir($dir); + } + } + } - return \OC\Files\Filesystem::normalizePath($shareFolder); + return $shareFolder; } /** diff --git a/apps/files_sharing/lib/sharedmount.php b/apps/files_sharing/lib/sharedmount.php index 4ad2d4e6b3e..3ffac0a5cb8 100644 --- a/apps/files_sharing/lib/sharedmount.php +++ b/apps/files_sharing/lib/sharedmount.php @@ -35,8 +35,8 @@ class SharedMount extends Mount implements MoveableMount { $mountPoint = basename($share['file_target']); $parent = dirname($share['file_target']); - while (!\OC\Files\Filesystem::is_dir($parent)) { - $parent = dirname($parent); + if (!\OC\Files\Filesystem::is_dir($parent)) { + $parent = Helper::getShareFolder(); } $newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget( diff --git a/apps/files_sharing/tests/helper.php b/apps/files_sharing/tests/helper.php index 6169a9f5094..ed332f28d4c 100644 --- a/apps/files_sharing/tests/helper.php +++ b/apps/files_sharing/tests/helper.php @@ -29,9 +29,11 @@ class Test_Files_Sharing_Helper extends Test_Files_Sharing_Base { function testSetGetShareFolder() { $this->assertSame('/', \OCA\Files_Sharing\Helper::getShareFolder()); - \OCA\Files_Sharing\Helper::setShareFolder('/Shared'); + \OCA\Files_Sharing\Helper::setShareFolder('/Shared/Folder'); - $this->assertSame('/Shared', \OCA\Files_Sharing\Helper::getShareFolder()); + $sharedFolder = \OCA\Files_Sharing\Helper::getShareFolder(); + $this->assertSame('/Shared/Folder', \OCA\Files_Sharing\Helper::getShareFolder()); + $this->assertTrue(\OC\Files\Filesystem::is_dir($sharedFolder)); // cleanup \OCP\Config::deleteSystemValue('share_folder');