Add storage priority support

Each storage backend has a default priority, assigned to any system mounts
created in ownCloud. mount.json can be manually modified to change these
priorities.

The priority order is as follows:
 * Personal
 * User
 * Group
 * Global

Within each mount type, the mount with the highest priority is active.

The storage backend defaults were chosen to be the following:
 * Local - 150
 * Remote storage - 100
 * SMB / CIFS with OC login - 90
This commit is contained in:
Robin McCorkell 2014-03-28 14:24:38 +00:00
parent 14a953fbe0
commit 05642733a3
2 changed files with 60 additions and 4 deletions

View File

@ -32,11 +32,13 @@ OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\SMB_OC', 'login
OC_Mount_Config::registerBackend('\OC\Files\Storage\Local', array(
'backend' => (string)$l->t('Local'),
'priority' => 150,
'configuration' => array(
'datadir' => (string)$l->t('Location'))));
OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', array(
'backend' => (string)$l->t('Amazon S3'),
'priority' => 100,
'configuration' => array(
'key' => (string)$l->t('Key'),
'secret' => '*'.$l->t('Secret'),
@ -45,6 +47,7 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', array(
OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', array(
'backend' => (string)$l->t('Amazon S3 and compliant'),
'priority' => 100,
'configuration' => array(
'key' => (string)$l->t('Access Key'),
'secret' => '*'.$l->t('Secret Key'),
@ -58,6 +61,7 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', array(
OC_Mount_Config::registerBackend('\OC\Files\Storage\Dropbox', array(
'backend' => 'Dropbox',
'priority' => 100,
'configuration' => array(
'configured' => '#configured',
'app_key' => (string)$l->t('App key'),
@ -69,6 +73,7 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\Dropbox', array(
OC_Mount_Config::registerBackend('\OC\Files\Storage\FTP', array(
'backend' => 'FTP',
'priority' => 100,
'configuration' => array(
'host' => (string)$l->t('Host'),
'user' => (string)$l->t('Username'),
@ -79,6 +84,7 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\FTP', array(
OC_Mount_Config::registerBackend('\OC\Files\Storage\Google', array(
'backend' => 'Google Drive',
'priority' => 100,
'configuration' => array(
'configured' => '#configured',
'client_id' => (string)$l->t('Client ID'),
@ -90,6 +96,7 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\Google', array(
OC_Mount_Config::registerBackend('\OC\Files\Storage\Swift', array(
'backend' => (string)$l->t('OpenStack Object Storage'),
'priority' => 100,
'configuration' => array(
'user' => (string)$l->t('Username (required)'),
'bucket' => (string)$l->t('Bucket (required)'),
@ -107,6 +114,7 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\Swift', array(
if (!OC_Util::runningOnWindows()) {
OC_Mount_Config::registerBackend('\OC\Files\Storage\SMB', array(
'backend' => 'SMB / CIFS',
'priority' => 100,
'configuration' => array(
'host' => (string)$l->t('Host'),
'user' => (string)$l->t('Username'),
@ -117,6 +125,7 @@ if (!OC_Util::runningOnWindows()) {
OC_Mount_Config::registerBackend('\OC\Files\Storage\SMB_OC', array(
'backend' => (string)$l->t('SMB / CIFS using OC login'),
'priority' => 90,
'configuration' => array(
'host' => (string)$l->t('Host'),
'username_as_share' => '!'.$l->t('Username as share'),
@ -127,6 +136,7 @@ if (!OC_Util::runningOnWindows()) {
OC_Mount_Config::registerBackend('\OC\Files\Storage\DAV', array(
'backend' => 'WebDAV',
'priority' => 100,
'configuration' => array(
'host' => (string)$l->t('URL'),
'user' => (string)$l->t('Username'),
@ -137,6 +147,7 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\DAV', array(
OC_Mount_Config::registerBackend('\OC\Files\Storage\OwnCloud', array(
'backend' => 'ownCloud',
'priority' => 100,
'configuration' => array(
'host' => (string)$l->t('URL'),
'user' => (string)$l->t('Username'),
@ -147,6 +158,7 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\OwnCloud', array(
OC_Mount_Config::registerBackend('\OC\Files\Storage\SFTP', array(
'backend' => 'SFTP',
'priority' => 100,
'configuration' => array(
'host' => (string)$l->t('Host'),
'user' => (string)$l->t('Username'),

View File

@ -126,6 +126,8 @@ class OC_Mount_Config {
$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
$mount_file = \OC_Config::getValue("mount_file", $datadir . "/mount.json");
$backends = self::getBackends();
//move config file to it's new position
if (is_file(\OC::$SERVERROOT . '/config/mount.json')) {
rename(\OC::$SERVERROOT . '/config/mount.json', $mount_file);
@ -136,7 +138,15 @@ class OC_Mount_Config {
if (isset($mountConfig[self::MOUNT_TYPE_GLOBAL])) {
foreach ($mountConfig[self::MOUNT_TYPE_GLOBAL] as $mountPoint => $options) {
$options['options'] = self::decryptPasswords($options['options']);
$mountPoints[$mountPoint] = $options;
if (!isset($options['priority'])) {
$options['priority'] = $backends[$options['class']]['priority'];
}
if ( (!isset($mountPoints[$mountPoint]))
|| ($options['priority'] >= $mountPoints[$mountPoint]['priority']) ) {
$options['priority_type'] = 'global';
$mountPoints[$mountPoint] = $options;
}
}
}
if (isset($mountConfig[self::MOUNT_TYPE_GROUP])) {
@ -148,7 +158,16 @@ class OC_Mount_Config {
$option = self::setUserVars($user, $option);
}
$options['options'] = self::decryptPasswords($options['options']);
$mountPoints[$mountPoint] = $options;
if (!isset($options['priority'])) {
$options['priority'] = $backends[$options['class']]['priority'];
}
if ( (!isset($mountPoints[$mountPoint]))
|| ($options['priority'] >= $mountPoints[$mountPoint]['priority'])
|| ($mountPoints[$mountPoint]['priority_type'] != 'group') ) {
$options['priority_type'] = 'group';
$mountPoints[$mountPoint] = $options;
}
}
}
}
@ -162,7 +181,16 @@ class OC_Mount_Config {
$option = self::setUserVars($user, $option);
}
$options['options'] = self::decryptPasswords($options['options']);
$mountPoints[$mountPoint] = $options;
if (!isset($options['priority'])) {
$options['priority'] = $backends[$options['class']]['priority'];
}
if ( (!isset($mountPoints[$mountPoint]))
|| ($options['priority'] >= $mountPoints[$mountPoint]['priority'])
|| ($mountPoints[$mountPoint]['priority_type'] != 'user') ) {
$options['priority_type'] = 'user';
$mountPoints[$mountPoint] = $options;
}
}
}
}
@ -173,7 +201,12 @@ class OC_Mount_Config {
if (isset($mountConfig[self::MOUNT_TYPE_USER][$user])) {
foreach ($mountConfig[self::MOUNT_TYPE_USER][$user] as $mountPoint => $options) {
$options['options'] = self::decryptPasswords($options['options']);
$mountPoints[$mountPoint] = $options;
if ( (!isset($mountPoints[$mountPoint]))
|| ($mountPoints[$mountPoint]['priority_type'] != 'personal') ) {
$options['priority_type'] = 'personal';
$mountPoints[$mountPoint] = $options;
}
}
}
@ -244,6 +277,9 @@ class OC_Mount_Config {
$mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15);
}
$mount['options'] = self::decryptPasswords($mount['options']);
if (!isset($mount['priority'])) {
$mount['priority'] = $backends[$mount['class']]['priority'];
}
// Remove '/$user/files/' from mount point
$mountPoint = substr($mountPoint, 13);
@ -251,6 +287,7 @@ class OC_Mount_Config {
'class' => $mount['class'],
'mountpoint' => $mountPoint,
'backend' => $backends[$mount['class']]['backend'],
'priority' => $mount['priority'],
'options' => $mount['options'],
'applicable' => array('groups' => array($group), 'users' => array()),
'status' => self::getBackendStatus($mount['class'], $mount['options'], false)
@ -275,12 +312,16 @@ class OC_Mount_Config {
$mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15);
}
$mount['options'] = self::decryptPasswords($mount['options']);
if (!isset($mount['priority'])) {
$mount['priority'] = $backends[$mount['class']]['priority'];
}
// Remove '/$user/files/' from mount point
$mountPoint = substr($mountPoint, 13);
$config = array(
'class' => $mount['class'],
'mountpoint' => $mountPoint,
'backend' => $backends[$mount['class']]['backend'],
'priority' => $mount['priority'],
'options' => $mount['options'],
'applicable' => array('groups' => array(), 'users' => array($user)),
'status' => self::getBackendStatus($mount['class'], $mount['options'], false)
@ -400,6 +441,9 @@ class OC_Mount_Config {
'options' => self::encryptPasswords($classOptions))
)
);
if (! $isPersonal) {
$mount[$applicable][$mountPoint]['priority'] = $backends[$class]['priority'];
}
$mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL);
$mountPoints = self::mergeMountPoints($mountPoints, $mount, $mountType);