/** * @brief Can be set up * @param string $user * @return boolean * @description configure the initial filesystem based on the configuration */ public static function setupFS($user = '') { //setting up the filesystem twice can only lead to trouble if (self::$fsSetup) { return false; } // If we are not forced to load a specific user we load the one that is logged in if ($user == "" && OC_User::isLoggedIn()) { $user = OC_User::getUser(); } // load all filesystem apps before, so no setup-hook gets lost if (!isset($RUNTIME_NOAPPS) || !$RUNTIME_NOAPPS) { OC_App::loadApps(array('filesystem')); } // the filesystem will finish when $user is not empty, // mark fs setup here to avoid doing the setup from loading // OC_Filesystem if ($user != '') { self::$fsSetup = true; } $configDataDirectory = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data"); //first set up the local "root" storage \OC\Files\Filesystem::initMounts(); if (!self::$rootMounted) { \OC\Files\Filesystem::mount('\\OC\\Files\\Storage\\Local', array('datadir' => $configDataDirectory), '/'); self::$rootMounted = true; } //if we aren't logged in, there is no use to set up the filesystem if ($user != "") { \OC\Files\Filesystem::addStorageWrapper(function ($mountPoint, $storage) { // set up quota for home storages, even for other users // which can happen when using sharing if ($storage instanceof \OC\Files\Storage\Home) { $user = $storage->getUser()->getUID(); $quota = OC_Util::getUserQuota($user); if ($quota !== \OC\Files\SPACE_UNLIMITED) { return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota)); } } return $storage; }); $userDir = '/' . $user . '/files'; $userRoot = OC_User::getHome($user); $userDirectory = $userRoot . '/files'; if (!is_dir($userDirectory)) { mkdir($userDirectory, 0755, true); OC_Util::copySkeleton($userDirectory); } //jail the user into his "home" directory \OC\Files\Filesystem::init($user, $userDir); $fileOperationProxy = new OC_FileProxy_FileOperations(); OC_FileProxy::register($fileOperationProxy); OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); } return 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' */ private static function initObjectStoreRootFS($config) { // check misconfiguration if (empty($config['class'])) { \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); } if (!isset($config['arguments'])) { $config['arguments'] = array(); } // instantiate object store implementation $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::initMounts(); if (!self::$rootMounted) { \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); self::$rootMounted = true; } }