public static function setupFS($user = "", $root = "files") { // configure the initial filesystem based on the configuration if (self::$fsSetup) { //setting up the filesystem twice can only lead to trouble return false; } $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data"); $CONFIG_BACKUPDIRECTORY = OC_Config::getValue("backupdirectory", OC::$SERVERROOT . "/backup"); // Check if config folder is writable. if (!is_writable(OC::$SERVERROOT . "/config/")) { $tmpl = new OC_Template('', 'error', 'guest'); $tmpl->assign('errors', array(1 => array('error' => "Can't write into config directory 'config'", 'hint' => "You can usually fix this by giving the webserver user write access to the config directory in owncloud"))); $tmpl->printPage(); exit; } // Check if apps folder is writable. if (!is_writable(OC::$SERVERROOT . "/apps/")) { $tmpl = new OC_Template('', 'error', 'guest'); $tmpl->assign('errors', array(1 => array('error' => "Can't write into apps directory 'apps'", 'hint' => "You can usually fix this by giving the webserver user write access to the config directory in owncloud"))); $tmpl->printPage(); exit; } // Create root dir. if (!is_dir($CONFIG_DATADIRECTORY_ROOT)) { $success = @mkdir($CONFIG_DATADIRECTORY_ROOT); if (!$success) { $tmpl = new OC_Template('', 'error', 'guest'); $tmpl->assign('errors', array(1 => array('error' => "Can't create data directory (" . $CONFIG_DATADIRECTORY_ROOT . ")", 'hint' => "You can usually fix this by giving the webserver write access to the ownCloud directory '" . OC::$SERVERROOT . "' (in a terminal, use the command 'chown -R www-data:www-data /path/to/your/owncloud/install/data' "))); $tmpl->printPage(); exit; } } // 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(); } //first set up the local "root" storage if (!self::$rootMounted) { OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY_ROOT), '/'); self::$rootMounted = true; } if ($user != "") { //if we aren't logged in, there is no use to set up the filesystem OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT . "/{$user}/{$root}"; if (!is_dir(OC::$CONFIG_DATADIRECTORY)) { mkdir(OC::$CONFIG_DATADIRECTORY, 0755, true); } //jail the user into his "home" directory OC_Filesystem::init('/' . $user . '/' . $root); $quotaProxy = new OC_FileProxy_Quota(); OC_FileProxy::register($quotaProxy); self::$fsSetup = true; } }
public static function setupFS($user = '') { // configure the initial filesystem based on the configuration if (self::$fsSetup) { //setting up the filesystem twice can only lead to trouble 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(); } // 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; } $CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data"); //first set up the local "root" storage if (!self::$rootMounted) { OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY), '/'); self::$rootMounted = true; } if ($user != "") { //if we aren't logged in, there is no use to set up the filesystem $user_dir = '/' . $user . '/files'; $user_root = OC_User::getHome($user); $userdirectory = $user_root . '/files'; if (!is_dir($userdirectory)) { mkdir($userdirectory, 0755, true); } //jail the user into his "home" directory OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $user_root), $user); OC_Filesystem::init($user_dir); $quotaProxy = new OC_FileProxy_Quota(); OC_FileProxy::register($quotaProxy); // Load personal mount config if (is_file($user_root . '/mount.php')) { $mountConfig = (include $user_root . '/mount.php'); if (isset($mountConfig['user'][$user])) { foreach ($mountConfig['user'][$user] as $mountPoint => $options) { OC_Filesystem::mount($options['class'], $options['options'], $mountPoint); } } $mtime = filemtime($user_root . '/mount.php'); $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0); if ($mtime > $previousMTime) { //mount config has changed, filecache needs to be updated OC_FileCache::triggerUpdate($user); OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime); } } OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir)); } }
public static function setupFS($user = '') { // configure the initial filesystem based on the configuration if (self::$fsSetup) { //setting up the filesystem twice can only lead to trouble 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; } $CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data"); //first set up the local "root" storage if (!self::$rootMounted) { OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY), '/'); self::$rootMounted = true; } if ($user != "") { //if we aren't logged in, there is no use to set up the filesystem $user_dir = '/' . $user . '/files'; $user_root = OC_User::getHome($user); $userdirectory = $user_root . '/files'; if (!is_dir($userdirectory)) { mkdir($userdirectory, 0755, true); } //jail the user into his "home" directory OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $user_root), $user); OC_Filesystem::init($user_dir, $user); $quotaProxy = new OC_FileProxy_Quota(); $fileOperationProxy = new OC_FileProxy_FileOperations(); OC_FileProxy::register($quotaProxy); OC_FileProxy::register($fileOperationProxy); // Load personal mount config self::loadUserMountPoints($user); OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir)); } }
/** * @return void */ public static function tearDownFS() { \OC\Files\Filesystem::tearDown(); self::$fsSetup = false; self::$rootMounted = false; }