Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add appdata_path option to store appdata locally outside primary storage. #9247

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@
'OC\\Files\\FileInfo' => $baseDir . '/lib/private/Files/FileInfo.php',
'OC\\Files\\Filesystem' => $baseDir . '/lib/private/Files/Filesystem.php',
'OC\\Files\\Mount\\CacheMountProvider' => $baseDir . '/lib/private/Files/Mount/CacheMountProvider.php',
'OC\\Files\\Mount\\AppdataMountProvider' => $baseDir . '/lib/private/Files/Mount/AppdataMountProvider.php',
'OC\\Files\\Mount\\LocalHomeMountProvider' => $baseDir . '/lib/private/Files/Mount/LocalHomeMountProvider.php',
'OC\\Files\\Mount\\Manager' => $baseDir . '/lib/private/Files/Mount/Manager.php',
'OC\\Files\\Mount\\MountPoint' => $baseDir . '/lib/private/Files/Mount/MountPoint.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Files\\FileInfo' => __DIR__ . '/../../..' . '/lib/private/Files/FileInfo.php',
'OC\\Files\\Filesystem' => __DIR__ . '/../../..' . '/lib/private/Files/Filesystem.php',
'OC\\Files\\Mount\\CacheMountProvider' => __DIR__ . '/../../..' . '/lib/private/Files/Mount/CacheMountProvider.php',
'OC\\Files\\Mount\\AppdataMountProvider' => __DIR__ . '/../../..' . '/lib/private/Files/Mount/AppdataMountProvider.php',
'OC\\Files\\Mount\\LocalHomeMountProvider' => __DIR__ . '/../../..' . '/lib/private/Files/Mount/LocalHomeMountProvider.php',
'OC\\Files\\Mount\\Manager' => __DIR__ . '/../../..' . '/lib/private/Files/Mount/Manager.php',
'OC\\Files\\Mount\\MountPoint' => __DIR__ . '/../../..' . '/lib/private/Files/Mount/MountPoint.php',
Expand Down
7 changes: 6 additions & 1 deletion lib/private/Files/AppData/AppData.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ private function getAppDataFolder() {
throw new \RuntimeException('no instance id!');
}

$name = 'appdata_' . $instanceId;
$appdataPath = $this->config->getValue('appdata_path', '');
if ($appdataPath !== '') {
$name = '/appdata.local/appdata_' . $instanceId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to have the separate /appdata.local/ just having the mount provider mount the appdata_path into /appdata_$instanceId should be sufficient

} else {
$name = 'appdata_' . $instanceId;
}

try {
$appDataFolder = $this->rootFolder->get($name);
Expand Down
63 changes: 63 additions & 0 deletions lib/private/Files/Mount/AppdataMountProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* @copyright Copyright (c) <2018>, <Patrik Novotný> (<patrik.novotny@gmx.com>)
*
* @author Patrik Novotný <patrik.novotny@gmx.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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\Mount;

use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
use OCP\IUser;

/**
* Mount provider for custom appdata storages
*/
class AppdataMountProvider implements IMountProvider {
/**
* @var IConfig
*/
private $config;

/**
* AppdataMountProvider constructor.
*
* @param IConfig $config
*/
public function __construct(IConfig $config) {
$this->config = $config;
}

/**
* Get the appdata mount for a user
*
* @param IUser $user
* @param IStorageFactory $loader
* @return \OCP\Files\Mount\IMountPoint[]
*/
public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$appdataPath = $this->config->getSystemValue('appdata_path', '');
if ($appdataPath !== '') {
return [new MountPoint('\OC\Files\Storage\Local', '/appdata.local', ['datadir' => $appdataPath])];
} else {
return [];
}
}
}
1 change: 1 addition & 0 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ public function __construct($webRoot, \OC\Config $config) {

$config = $c->getConfig();
$manager->registerProvider(new CacheMountProvider($config));
$manager->registerProvider(new AppdataMountProvider($config));
$manager->registerHomeProvider(new LocalHomeMountProvider());
$manager->registerHomeProvider(new ObjectHomeMountProvider($config));

Expand Down