summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/config.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-03-26 14:30:35 +0100
committerVincent Petry <pvince81@owncloud.com>2014-03-26 14:30:35 +0100
commitb656c68edee995e17f6eb1febe2a1d620564a2c9 (patch)
tree075a3204cfced39772acc21659ca6bb2bf39e6c8 /apps/files_external/lib/config.php
parent028973cbea865075a32db6228b56b7d3960771d6 (diff)
parente002b7242cb19a0e028d325cd64b57e67dc48108 (diff)
downloadnextcloud-server-b656c68edee995e17f6eb1febe2a1d620564a2c9.tar.gz
nextcloud-server-b656c68edee995e17f6eb1febe2a1d620564a2c9.zip
Merge pull request #7888 from owncloud/extstorage-multiplemountpointconfig
Fix merging of external storage configurations
Diffstat (limited to 'apps/files_external/lib/config.php')
-rwxr-xr-xapps/files_external/lib/config.php78
1 files changed, 52 insertions, 26 deletions
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index c5b091336e1..f7caafb74aa 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -304,18 +304,23 @@ class OC_Mount_Config {
$mount['options'] = self::decryptPasswords($mount['options']);
// Remove '/$user/files/' from mount point
$mountPoint = substr($mountPoint, 13);
- // Merge the mount point into the current mount points
- if (isset($system[$mountPoint]) && $system[$mountPoint]['configuration'] == $mount['options']) {
- $system[$mountPoint]['applicable']['groups']
- = array_merge($system[$mountPoint]['applicable']['groups'], array($group));
+
+ $config = array(
+ 'class' => $mount['class'],
+ 'mountpoint' => $mountPoint,
+ 'backend' => $backends[$mount['class']]['backend'],
+ 'options' => $mount['options'],
+ 'applicable' => array('groups' => array($group), 'users' => array()),
+ 'status' => self::getBackendStatus($mount['class'], $mount['options'])
+ );
+ $hash = self::makeConfigHash($config);
+ // If an existing config exists (with same class, mountpoint and options)
+ if (isset($system[$hash])) {
+ // add the groups into that config
+ $system[$hash]['applicable']['groups']
+ = array_merge($system[$hash]['applicable']['groups'], array($group));
} else {
- $system[$mountPoint] = array(
- 'class' => $mount['class'],
- 'backend' => $backends[$mount['class']]['backend'],
- 'configuration' => $mount['options'],
- 'applicable' => array('groups' => array($group), 'users' => array()),
- 'status' => self::getBackendStatus($mount['class'], $mount['options'])
- );
+ $system[$hash] = $config;
}
}
}
@@ -330,23 +335,27 @@ class OC_Mount_Config {
$mount['options'] = self::decryptPasswords($mount['options']);
// Remove '/$user/files/' from mount point
$mountPoint = substr($mountPoint, 13);
- // Merge the mount point into the current mount points
- if (isset($system[$mountPoint]) && $system[$mountPoint]['configuration'] == $mount['options']) {
- $system[$mountPoint]['applicable']['users']
- = array_merge($system[$mountPoint]['applicable']['users'], array($user));
+ $config = array(
+ 'class' => $mount['class'],
+ 'mountpoint' => $mountPoint,
+ 'backend' => $backends[$mount['class']]['backend'],
+ 'options' => $mount['options'],
+ 'applicable' => array('groups' => array(), 'users' => array($user)),
+ 'status' => self::getBackendStatus($mount['class'], $mount['options'])
+ );
+ $hash = self::makeConfigHash($config);
+ // If an existing config exists (with same class, mountpoint and options)
+ if (isset($system[$hash])) {
+ // add the users into that config
+ $system[$hash]['applicable']['users']
+ = array_merge($system[$hash]['applicable']['users'], array($user));
} else {
- $system[$mountPoint] = array(
- 'class' => $mount['class'],
- 'backend' => $backends[$mount['class']]['backend'],
- 'configuration' => $mount['options'],
- 'applicable' => array('groups' => array(), 'users' => array($user)),
- 'status' => self::getBackendStatus($mount['class'], $mount['options'])
- );
+ $system[$hash] = $config;
}
}
}
}
- return $system;
+ return array_values($system);
}
/**
@@ -366,11 +375,12 @@ class OC_Mount_Config {
$mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15);
}
$mount['options'] = self::decryptPasswords($mount['options']);
- // Remove '/uid/files/' from mount point
- $personal[substr($mountPoint, strlen($uid) + 8)] = array(
+ $personal[] = array(
'class' => $mount['class'],
+ // Remove '/uid/files/' from mount point
+ 'mountpoint' => substr($mountPoint, strlen($uid) + 8),
'backend' => $backends[$mount['class']]['backend'],
- 'configuration' => $mount['options'],
+ 'options' => $mount['options'],
'status' => self::getBackendStatus($mount['class'], $mount['options'])
);
}
@@ -712,4 +722,20 @@ class OC_Mount_Config {
$cipher->setKey(\OCP\Config::getSystemValue('passwordsalt'));
return $cipher;
}
+
+ /**
+ * Computes a hash based on the given configuration.
+ * This is mostly used to find out whether configurations
+ * are the same.
+ */
+ private static function makeConfigHash($config) {
+ $data = json_encode(
+ array(
+ 'c' => $config['class'],
+ 'm' => $config['mountpoint'],
+ 'o' => $config['options']
+ )
+ );
+ return hash('md5', $data);
+ }
}