Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
using LegacyUtil to not depend on OC_Mount_Config if possible, re int…
…roduced makeConfigHash, fixed some minor things
  • Loading branch information
phisch committed Aug 14, 2017
commit ed1a7e42c315f2aa781bbaa4163e0a67f276d5f6
22 changes: 22 additions & 0 deletions lib/private/Files/External/LegacyUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,26 @@ private static function getCipher() {
$cipher->setKey(\OC::$server->getConfig()->getSystemValue('passwordsalt', null));
return $cipher;
}

/**
* Computes a hash based on the given configuration.
* This is mostly used to find out whether configurations
* are the same.
*
* @param array $config
* @return string
*/
public static function makeConfigHash($config) {
$data = json_encode(
array(
'c' => $config['backend'],
'a' => $config['authMechanism'],
'm' => $config['mountpoint'],
'o' => $config['options'],
'p' => isset($config['priority']) ? $config['priority'] : -1,
'mo' => isset($config['mountOptions']) ? $config['mountOptions'] : [],
)
);
return hash('md5', $data);
}
}
38 changes: 21 additions & 17 deletions lib/private/Files/External/Service/LegacyStoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,41 @@
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OC\Files\External\Service;
use OC\Files\External\LegacyUtil;
use OC\Files\External\StorageConfig;
use OCP\Files\External\IStoragesBackendService;
use OCP\Util;

/**
* Read mount config from legacy mount.json
*/
class LegacyStoragesService {
/** @var IStoragesBackendService */
/**
* @var IStoragesBackendService
*/
protected $backendService;

/**
* LegacyStoragesService constructor.
*
* @var LegacyUtil
*/
private $legacyUtil;

/**
* @param IStoragesBackendService $backendService
*/
public function __construct(IStoragesBackendService $backendService) {
$this->backendService = $backendService;
$this->legacyUtil = new LegacyUtil();
}


/**
* Read legacy config data
*
* @return array list of mount configs
*/
protected function readLegacyConfig() {
$mountConfig = new \OC_Mount_Config();
return $mountConfig->readData();
return $this->legacyUtil->readData();
}

/**
Expand Down Expand Up @@ -90,13 +93,14 @@ protected function populateStorageConfigWithLegacyOptions(
$storageOptions['priority'] = $backend->getPriority();
}
$storageConfig->setPriority($storageOptions['priority']);
if ($mountType === \OC_Mount_Config::MOUNT_TYPE_USER) {

if ($mountType === LegacyUtil::MOUNT_TYPE_USER) {
$applicableUsers = $storageConfig->getApplicableUsers();
if ($applicable !== 'all') {
$applicableUsers[] = $applicable;
$storageConfig->setApplicableUsers($applicableUsers);
}
} else if ($mountType === \OC_Mount_Config::MOUNT_TYPE_GROUP) {
} else if ($mountType === LegacyUtil::MOUNT_TYPE_GROUP) {
$applicableGroups = $storageConfig->getApplicableGroups();
$applicableGroups[] = $applicable;
$storageConfig->setApplicableGroups($applicableGroups);
Expand Down Expand Up @@ -151,10 +155,10 @@ public function getAllStorages() {
$parts = explode('/', ltrim($rootMountPath, '/'), 3);
if (count($parts) < 3) {
// something went wrong, skip
\OCP\Util::writeLog(
Util::writeLog(
'files_external',
'Could not parse mount point "' . $rootMountPath . '"',
\OCP\Util::ERROR
Util::ERROR
);
continue;
}
Expand All @@ -179,7 +183,7 @@ public function getAllStorages() {
// but at this point we don't know the max-id, so use
// first group it by config hash
$storageOptions['mountpoint'] = $rootMountPath;
$configId = \OC_Mount_Config::makeConfigHash($storageOptions);
$configId = LegacyUtil::makeConfigHash($storageOptions);
if (isset($storagesWithConfigHash[$configId])) {
$currentStorage = $storagesWithConfigHash[$configId];
}
Expand All @@ -202,11 +206,11 @@ public function getAllStorages() {
$storagesWithConfigHash[$configId] = $currentStorage;
}
} catch (\UnexpectedValueException $e) {
// dont die if a storage backend doesn't exist
\OCP\Util::writeLog(
// don't die if a storage backend doesn't exist
Util::writeLog(
'files_external',
'Could not load storage: "' . $e->getMessage() . '"',
\OCP\Util::ERROR
Util::ERROR
);
}
}
Expand Down