Create public function initMountPoints() for initializing a specified user's mount points

This commit is contained in:
Michael Gapczynski 2012-11-22 00:44:48 -05:00
parent 77fdb16b7c
commit b76d1afe19
2 changed files with 37 additions and 32 deletions

View file

@ -229,35 +229,50 @@ class Filesystem {
self::$defaultInstance = new View($root);
//load custom mount config
if (is_file(\OC::$SERVERROOT . '/config/mount.php')) {
self::initMountPoints();
self::$loaded = true;
return true;
}
/**
* Initialize system and personal mount points for a user
*
* @param string $user
*/
public static function initMountPoints($user = '') {
if ($user == '') {
$user = \OC_User::getUser();
}
// Load system mount points
if (is_file(\OC::$SERVERROOT.'/config/mount.php')) {
$mountConfig = include 'config/mount.php';
if (isset($mountConfig['global'])) {
foreach ($mountConfig['global'] as $mountPoint => $options) {
self::mount($options['class'], $options['options'], $mountPoint);
}
}
if (isset($mountConfig['group'])) {
foreach ($mountConfig['group'] as $group => $mounts) {
if (\OC_Group::inGroup(\OC_User::getUser(), $group)) {
if (\OC_Group::inGroup($user, $group)) {
foreach ($mounts as $mountPoint => $options) {
$mountPoint = self::setUserVars($mountPoint);
$mountPoint = self::setUserVars($user, $mountPoint);
foreach ($options as &$option) {
$option = self::setUserVars($option);
$option = self::setUserVars($user, $option);
}
self::mount($options['class'], $options['options'], $mountPoint);
}
}
}
}
if (isset($mountConfig['user'])) {
foreach ($mountConfig['user'] as $user => $mounts) {
if ($user === 'all' or strtolower($user) === strtolower(\OC_User::getUser())) {
foreach ($mountConfig['user'] as $mountUser => $mounts) {
if ($user === 'all' or strtolower($mountUser) === strtolower($user)) {
foreach ($mounts as $mountPoint => $options) {
$mountPoint = self::setUserVars($mountPoint);
$mountPoint = self::setUserVars($user, $mountPoint);
foreach ($options as &$option) {
$option = self::setUserVars($option);
$option = self::setUserVars($user, $option);
}
self::mount($options['class'], $options['options'], $mountPoint);
}
@ -265,10 +280,16 @@ class Filesystem {
}
}
}
self::$loaded = true;
return true;
// Load personal mount points
$root = OC_User::getHome($user);
if (is_file($root.'/mount.php')) {
$mountConfig = include $root.'/mount.php';
if (isset($mountConfig['user'][$user])) {
foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
self::mount($options['class'], $options['options'], $mountPoint);
}
}
}
}
/**
@ -277,8 +298,8 @@ class Filesystem {
* @param string $input
* @return string
*/
private static function setUserVars($input) {
return str_replace('$user', \OC_User::getUser(), $input);
private static function setUserVars($user, $input) {
return str_replace('$user', $user, $input);
}
/**

View file

@ -58,8 +58,6 @@ class OC_Util {
$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));
}
@ -71,20 +69,6 @@ class OC_Util {
self::$fsSetup=false;
}
public static function loadUserMountPoints($user) {
$user_dir = '/'.$user.'/files';
$user_root = OC_User::getHome($user);
$userdirectory = $user_root . '/files';
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\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
}
}
}
}
/**
* get the current installed version of ownCloud
* @return array