Skip to content

Commit

Permalink
Merge pull request #8293 from owncloud/files_external_fix_readData
Browse files Browse the repository at this point in the history
Fix issue with personal mount points and sharing
  • Loading branch information
Vincent Petry committed May 8, 2014
2 parents 390549c + abfd7ec commit af2b763
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions apps/files_external/lib/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static function getAbsoluteMountPoints($user) {
}

// Load system mount points
$mountConfig = self::readData(false);
$mountConfig = self::readData();
if (isset($mountConfig[self::MOUNT_TYPE_GLOBAL])) {
foreach ($mountConfig[self::MOUNT_TYPE_GLOBAL] as $mountPoint => $options) {
$options['options'] = self::decryptPasswords($options['options']);
Expand Down Expand Up @@ -169,7 +169,7 @@ public static function getAbsoluteMountPoints($user) {
}

// Load personal mount points
$mountConfig = self::readData(true);
$mountConfig = self::readData($user);
if (isset($mountConfig[self::MOUNT_TYPE_USER][$user])) {
foreach ($mountConfig[self::MOUNT_TYPE_USER][$user] as $mountPoint => $options) {
$options['options'] = self::decryptPasswords($options['options']);
Expand Down Expand Up @@ -233,7 +233,7 @@ public static function getPersonalBackends() {
* @return array
*/
public static function getSystemMountPoints() {
$mountPoints = self::readData(false);
$mountPoints = self::readData();
$backends = self::getBackends();
$system = array();
if (isset($mountPoints[self::MOUNT_TYPE_GROUP])) {
Expand Down Expand Up @@ -306,7 +306,7 @@ public static function getSystemMountPoints() {
* @return array
*/
public static function getPersonalMountPoints() {
$mountPoints = self::readData(true);
$mountPoints = self::readData(OCP\User::getUser());
$backEnds = self::getBackends();
$uid = OCP\User::getUser();
$personal = array();
Expand Down Expand Up @@ -400,7 +400,7 @@ public static function addMountPoint($mountPoint,
'options' => self::encryptPasswords($classOptions))
)
);
$mountPoints = self::readData($isPersonal);
$mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL);
// Merge the new mount point into the current mount points
if (isset($mountPoints[$mountType])) {
if (isset($mountPoints[$mountType][$applicable])) {
Expand All @@ -412,7 +412,7 @@ public static function addMountPoint($mountPoint,
} else {
$mountPoints[$mountType] = $mount;
}
self::writeData($isPersonal, $mountPoints);
self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints);
return self::getBackendStatus($class, $classOptions, $isPersonal);
}

Expand All @@ -434,7 +434,7 @@ public static function removeMountPoint($mountPoint, $mountType, $applicable, $i
} else {
$mountPoint = '/$user/files/'.ltrim($mountPoint, '/');
}
$mountPoints = self::readData($isPersonal);
$mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL);
// Remove mount point
unset($mountPoints[$mountType][$applicable][$mountPoint]);
// Unset parent arrays if empty
Expand All @@ -444,20 +444,20 @@ public static function removeMountPoint($mountPoint, $mountType, $applicable, $i
unset($mountPoints[$mountType]);
}
}
self::writeData($isPersonal, $mountPoints);
self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints);
return true;
}

/**
* Read the mount points in the config file into an array
* @param boolean $isPersonal Personal or system config file
* @param string|null $user If not null, personal for $user, otherwise system
* @return array
*/
private static function readData($isPersonal) {
private static function readData($user = NULL) {
$parser = new \OC\ArrayParser();
if ($isPersonal) {
$phpFile = OC_User::getHome(OCP\User::getUser()).'/mount.php';
$jsonFile = OC_User::getHome(OCP\User::getUser()).'/mount.json';
if (isset($user)) {
$phpFile = OC_User::getHome($user).'/mount.php';
$jsonFile = OC_User::getHome($user).'/mount.json';
} else {
$phpFile = OC::$SERVERROOT.'/config/mount.php';
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
Expand All @@ -479,13 +479,12 @@ private static function readData($isPersonal) {

/**
* Write the mount points to the config file
* @param bool Personal or system config file
* @param array Mount points
* @param boolean $isPersonal
* @param string|null $user If not null, personal for $user, otherwise system
* @param array $data Mount points
*/
private static function writeData($isPersonal, $data) {
if ($isPersonal) {
$file = OC_User::getHome(OCP\User::getUser()).'/mount.json';
private static function writeData($user, $data) {
if (isset($user)) {
$file = OC_User::getHome($user).'/mount.json';
} else {
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
$file = \OC_Config::getValue('mount_file', $datadir . '/mount.json');
Expand Down

0 comments on commit af2b763

Please sign in to comment.