diff options
Diffstat (limited to 'lib/private/legacy')
-rw-r--r-- | lib/private/legacy/OC_App.php | 12 | ||||
-rw-r--r-- | lib/private/legacy/OC_Files.php | 1 | ||||
-rw-r--r-- | lib/private/legacy/OC_Helper.php | 39 | ||||
-rw-r--r-- | lib/private/legacy/OC_Response.php | 1 | ||||
-rw-r--r-- | lib/private/legacy/OC_Template.php | 2 | ||||
-rw-r--r-- | lib/private/legacy/OC_Util.php | 261 |
6 files changed, 61 insertions, 255 deletions
diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index ca01e91216b..f290b7a610c 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -629,11 +629,21 @@ class OC_App { * @return string */ public static function getCurrentApp(): string { + if (\OC::$CLI) { + return ''; + } + $request = \OC::$server->getRequest(); $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); $topFolder = substr($script, 0, strpos($script, '/') ?: 0); if (empty($topFolder)) { - $path_info = $request->getPathInfo(); + try { + $path_info = $request->getPathInfo(); + } catch (Exception $e) { + // Can happen from unit tests because the script name is `./vendor/bin/phpunit` or something a like then. + \OC::$server->get(LoggerInterface::class)->error('Failed to detect current app from script path', ['exception' => $e]); + return ''; + } if ($path_info) { $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); } diff --git a/lib/private/legacy/OC_Files.php b/lib/private/legacy/OC_Files.php index d1af5b24bdd..41ac20577b2 100644 --- a/lib/private/legacy/OC_Files.php +++ b/lib/private/legacy/OC_Files.php @@ -98,6 +98,7 @@ class OC_Files { } } header('Content-Type: '.$type, true); + header('X-Accel-Buffering: no'); } /** diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index efb9252e346..0d1903007c2 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -44,8 +44,11 @@ * */ use bantu\IniGetWrapper\IniGetWrapper; +use OC\Files\Filesystem; use OCP\Files\Mount\IMountPoint; +use OCP\ICacheFactory; use OCP\IUser; +use Psr\Log\LoggerInterface; use Symfony\Component\Process\ExecutableFinder; /** @@ -485,17 +488,28 @@ class OC_Helper { * @return array * @throws \OCP\Files\NotFoundException */ - public static function getStorageInfo($path, $rootInfo = null) { + public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true) { + /** @var ICacheFactory $cacheFactory */ + $cacheFactory = \OC::$server->get(ICacheFactory::class); + $memcache = $cacheFactory->createLocal('storage_info'); + // return storage info without adding mount points $includeExtStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false); + $fullPath = Filesystem::getView()->getAbsolutePath($path); + $cacheKey = $fullPath. '::' . ($includeMountPoints ? 'include' : 'exclude'); + $cached = $memcache->get($cacheKey); + if ($cached) { + return $cached; + } + if (!$rootInfo) { $rootInfo = \OC\Files\Filesystem::getFileInfo($path, $includeExtStorage ? 'ext' : false); } if (!$rootInfo instanceof \OCP\Files\FileInfo) { throw new \OCP\Files\NotFoundException(); } - $used = $rootInfo->getSize(); + $used = $rootInfo->getSize($includeMountPoints); if ($used < 0) { $used = 0; } @@ -505,7 +519,6 @@ class OC_Helper { $sourceStorage = $storage; if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { $includeExtStorage = false; - $sourceStorage = $storage->getSourceStorage(); $internalPath = $storage->getUnjailedPath($rootInfo->getInternalPath()); } else { $internalPath = $rootInfo->getInternalPath(); @@ -531,7 +544,19 @@ class OC_Helper { /** @var \OC\Files\Storage\Wrapper\Quota $storage */ $quota = $sourceStorage->getQuota(); } - $free = $sourceStorage->free_space($internalPath); + try { + $free = $sourceStorage->free_space($internalPath); + } catch (\Exception $e) { + if ($path === "") { + throw $e; + } + /** @var LoggerInterface $logger */ + $logger = \OC::$server->get(LoggerInterface::class); + $logger->warning("Error while getting quota info, using root quota", ['exception' => $e]); + $rootInfo = self::getStorageInfo(""); + $memcache->set($cacheKey, $rootInfo, 5 * 60); + return $rootInfo; + } if ($free >= 0) { $total = $free + $used; } else { @@ -559,7 +584,7 @@ class OC_Helper { [,,,$mountPoint] = explode('/', $mount->getMountPoint(), 4); } - return [ + $info = [ 'free' => $free, 'used' => $used, 'quota' => $quota, @@ -570,6 +595,10 @@ class OC_Helper { 'mountType' => $mount->getMountType(), 'mountPoint' => trim($mountPoint, '/'), ]; + + $memcache->set($cacheKey, $info, 5 * 60); + + return $info; } /** diff --git a/lib/private/legacy/OC_Response.php b/lib/private/legacy/OC_Response.php index 6cfd53d2651..e4525fe9e10 100644 --- a/lib/private/legacy/OC_Response.php +++ b/lib/private/legacy/OC_Response.php @@ -97,7 +97,6 @@ class OC_Response { if (getenv('modHeadersAvailable') !== 'true') { header('Referrer-Policy: no-referrer'); // https://www.w3.org/TR/referrer-policy/ header('X-Content-Type-Options: nosniff'); // Disable sniffing the content type for IE - header('X-Download-Options: noopen'); // https://msdn.microsoft.com/en-us/library/jj542450(v=vs.85).aspx header('X-Frame-Options: SAMEORIGIN'); // Disallow iFraming from other domains header('X-Permitted-Cross-Domain-Policies: none'); // https://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html header('X-Robots-Tag: none'); // https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag diff --git a/lib/private/legacy/OC_Template.php b/lib/private/legacy/OC_Template.php index 16ad7273cd2..b7a400d3269 100644 --- a/lib/private/legacy/OC_Template.php +++ b/lib/private/legacy/OC_Template.php @@ -105,7 +105,7 @@ class OC_Template extends \OC\Template\Base { // apps that started before the template initialization can load their own scripts/styles // so to make sure this scripts/styles here are loaded first we put all core scripts first // check lib/public/Util.php - OC_Util::addStyle('css-variables', null, true); + // OC_Util::addStyle('css-variables', null, true); OC_Util::addStyle('server', null, true); // include common nextcloud webpack bundle diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index c4606383666..8debe7a8968 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -66,11 +66,10 @@ use bantu\IniGetWrapper\IniGetWrapper; use OC\AppFramework\Http\Request; -use OC\Files\Storage\LocalRootStorage; +use OC\Files\SetupManager; use OCP\Files\Template\ITemplateManager; use OCP\IConfig; use OCP\IGroupManager; -use OCP\ILogger; use OCP\IURLGenerator; use OCP\IUser; use OCP\Share\IManager; @@ -80,9 +79,6 @@ class OC_Util { public static $scripts = []; public static $styles = []; public static $headers = []; - private static $rootMounted = false; - private static $rootFsSetup = false; - private static $fsSetup = false; /** @var array Local cache of version.php */ private static $versionCache = null; @@ -91,222 +87,6 @@ class OC_Util { return \OC::$server->getAppManager(); } - private static function initLocalStorageRootFS() { - // mount local file backend as root - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); - //first set up the local "root" storage - \OC\Files\Filesystem::initMountManager(); - if (!self::$rootMounted) { - \OC\Files\Filesystem::mount(LocalRootStorage::class, ['datadir' => $configDataDirectory], '/'); - self::$rootMounted = true; - } - } - - /** - * mounting an object storage as the root fs will in essence remove the - * necessity of a data folder being present. - * TODO make home storage aware of this and use the object storage instead of local disk access - * - * @param array $config containing 'class' and optional 'arguments' - * @suppress PhanDeprecatedFunction - */ - private static function initObjectStoreRootFS($config) { - // check misconfiguration - if (empty($config['class'])) { - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); - } - if (!isset($config['arguments'])) { - $config['arguments'] = []; - } - - // instantiate object store implementation - $name = $config['class']; - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { - $segments = explode('\\', $name); - OC_App::loadApp(strtolower($segments[1])); - } - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); - // mount with plain / root object store implementation - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; - - // mount object storage as root - \OC\Files\Filesystem::initMountManager(); - if (!self::$rootMounted) { - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); - self::$rootMounted = true; - } - } - - /** - * mounting an object storage as the root fs will in essence remove the - * necessity of a data folder being present. - * - * @param array $config containing 'class' and optional 'arguments' - * @suppress PhanDeprecatedFunction - */ - private static function initObjectStoreMultibucketRootFS($config) { - // check misconfiguration - if (empty($config['class'])) { - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); - } - if (!isset($config['arguments'])) { - $config['arguments'] = []; - } - - // instantiate object store implementation - $name = $config['class']; - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { - $segments = explode('\\', $name); - OC_App::loadApp(strtolower($segments[1])); - } - - if (!isset($config['arguments']['bucket'])) { - $config['arguments']['bucket'] = ''; - } - // put the root FS always in first bucket for multibucket configuration - $config['arguments']['bucket'] .= '0'; - - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); - // mount with plain / root object store implementation - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; - - // mount object storage as root - \OC\Files\Filesystem::initMountManager(); - if (!self::$rootMounted) { - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); - self::$rootMounted = true; - } - } - - /** - * Can be set up - * - * @param string $user - * @return boolean - * @description configure the initial filesystem based on the configuration - * @suppress PhanDeprecatedFunction - * @suppress PhanAccessMethodInternal - */ - public static function setupRootFS(string $user = '') { - //setting up the filesystem twice can only lead to trouble - if (self::$rootFsSetup) { - return false; - } - - \OC::$server->getEventLogger()->start('setup_root_fs', 'Setup root filesystem'); - - // load all filesystem apps before, so no setup-hook gets lost - OC_App::loadApps(['filesystem']); - - self::$rootFsSetup = true; - - \OC\Files\Filesystem::initMountManager(); - - $prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { - if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { - /** @var \OC\Files\Storage\Common $storage */ - $storage->setMountOptions($mount->getOptions()); - } - return $storage; - }); - - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { - if (!$mount->getOption('enable_sharing', true)) { - return new \OC\Files\Storage\Wrapper\PermissionsMask([ - 'storage' => $storage, - 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE - ]); - } - return $storage; - }); - - // install storage availability wrapper, before most other wrappers - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { - return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); - } - return $storage; - }); - - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { - return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); - } - return $storage; - }); - - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { - // set up quota for home storages, even for other users - // which can happen when using sharing - - /** - * @var \OC\Files\Storage\Storage $storage - */ - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') - ) { - /** @var \OC\Files\Storage\Home $storage */ - if (is_object($storage->getUser())) { - $quota = OC_Util::getUserQuota($storage->getUser()); - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { - return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']); - } - } - } - - return $storage; - }); - - \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { - /* - * Do not allow any operations that modify the storage - */ - if ($mount->getOption('readonly', false)) { - return new \OC\Files\Storage\Wrapper\PermissionsMask([ - 'storage' => $storage, - 'mask' => \OCP\Constants::PERMISSION_ALL & ~( - \OCP\Constants::PERMISSION_UPDATE | - \OCP\Constants::PERMISSION_CREATE | - \OCP\Constants::PERMISSION_DELETE - ), - ]); - } - return $storage; - }); - - OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user]); - - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); - - //check if we are using an object storage - $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); - $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); - - // use the same order as in ObjectHomeMountProvider - if (isset($objectStoreMultibucket)) { - self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); - } elseif (isset($objectStore)) { - self::initObjectStoreRootFS($objectStore); - } else { - self::initLocalStorageRootFS(); - } - - /** @var \OCP\Files\Config\IMountProviderCollection $mountProviderCollection */ - $mountProviderCollection = \OC::$server->query(\OCP\Files\Config\IMountProviderCollection::class); - $rootMountProviders = $mountProviderCollection->getRootMounts(); - - /** @var \OC\Files\Mount\Manager $mountManager */ - $mountManager = \OC\Files\Filesystem::getMountManager(); - foreach ($rootMountProviders as $rootMountProvider) { - $mountManager->addMount($rootMountProvider); - } - - \OC::$server->getEventLogger()->end('setup_root_fs'); - - return true; - } - /** * Setup the file system * @@ -317,14 +97,6 @@ class OC_Util { * @suppress PhanAccessMethodInternal */ public static function setupFS(?string $user = '') { - self::setupRootFS($user ?? ''); - - if (self::$fsSetup) { - return false; - } - - \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); - // If we are not forced to load a specific user we load the one that is logged in if ($user === '') { $userObject = \OC::$server->get(\OCP\IUserSession::class)->getUser(); @@ -332,31 +104,28 @@ class OC_Util { $userObject = \OC::$server->get(\OCP\IUserManager::class)->get($user); } - //if we aren't logged in, or the user doesn't exist, there is no use to set up the filesystem - if ($userObject) { - self::$fsSetup = true; - - $userDir = '/' . $userObject->getUID() . '/files'; - - //jail the user into his "home" directory - \OC\Files\Filesystem::init($userObject, $userDir); + /** @var SetupManager $setupManager */ + $setupManager = \OC::$server->get(SetupManager::class); - OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $userObject->getUID(), 'user_dir' => $userDir]); + if ($userObject) { + $setupManager->setupForUser($userObject); + } else { + $setupManager->setupRoot(); } - \OC::$server->getEventLogger()->end('setup_fs'); return true; } /** - * check if a password is required for each public link + * Check if a password is required for each public link * + * @param bool $checkGroupMembership Check group membership exclusion * @return boolean * @suppress PhanDeprecatedFunction */ - public static function isPublicLinkPasswordRequired() { + public static function isPublicLinkPasswordRequired(bool $checkGroupMembership = true) { /** @var IManager $shareManager */ $shareManager = \OC::$server->get(IManager::class); - return $shareManager->shareApiLinkEnforcePassword(); + return $shareManager->shareApiLinkEnforcePassword($checkGroupMembership); } /** @@ -497,11 +266,9 @@ class OC_Util { * @suppress PhanUndeclaredMethod */ public static function tearDownFS() { - \OC\Files\Filesystem::tearDown(); - \OC::$server->getRootFolder()->clearCache(); - self::$fsSetup = false; - self::$rootFsSetup = false; - self::$rootMounted = false; + /** @var SetupManager $setupManager */ + $setupManager = \OC::$server->get(SetupManager::class); + $setupManager->tearDown(); } /** |