Skip to content

Commit

Permalink
Update AppData.php
Browse files Browse the repository at this point in the history
Allow configuring the location of the appdata folder

Signed-off-by: summersab <arthur.summers@gmail.com>
Signed-off-by: summersab <18727110+summersab@users.noreply.github.com>

Set type of `$rootFolder`

Signed-off-by: summersab <arthur.summers@gmail.com>
Signed-off-by: summersab <18727110+summersab@users.noreply.github.com>

implement test method

Signed-off-by: summersab <18727110+summersab@users.noreply.github.com>

update `config.sample.php` with `appdataroot` parameter

Signed-off-by: summersab <18727110+summersab@users.noreply.github.com>
  • Loading branch information
summersab committed Jan 28, 2023
1 parent 75d7203 commit 145000e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
10 changes: 10 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,16 @@
*/
'updatedirectory' => '',

/**
* Override where Nextcloud stores the ``appdata_INSTANCEID`` directory. Useful
* when using remote object storage where local system disks provide faster data
* access or when using shared storage for ``appdata_INSTANCEID`` between
* multiple Nextcloud systems. Defaults to `datadirectory` if unset.
*
* The Web server user must have write access to this directory.
*/
'appdataroot' => '',

/**
* Blacklist a specific file or files and disallow the upload of files
* with this name. ``.htaccess`` is blocked by default.
Expand Down
25 changes: 24 additions & 1 deletion lib/private/Files/AppData/AppData.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

use OCP\Cache\CappedMemoryCache;
use OC\Files\SimpleFS\SimpleFolder;
use OC\Files\Node\LazyRoot;
use OC\Files\Storage\LocalRootStorage;
use OC\Files\Mount\MountPoint;
use OC\SystemConfig;
use OCP\Files\Folder;
use OCP\Files\IAppData;
Expand Down Expand Up @@ -55,10 +58,30 @@ class AppData implements IAppData {
public function __construct(IRootFolder $rootFolder,
SystemConfig $systemConfig,
string $appId) {
$this->rootFolder = $rootFolder;
$this->config = $systemConfig;
$this->appId = $appId;
$this->folders = new CappedMemoryCache();

$this->rootFolder = new LazyRoot(function () use ($rootFolder, $systemConfig) {
if ($appdataroot = $systemConfig->getValue('appdataroot', null)) {
$instanceId = $systemConfig->getValue('instanceid', null);
if ($instanceId === null) {
throw new \RuntimeException('no instance id!');
}

$folderName = 'appdata_' . $instanceId;

$arguments = [
'datadir' => $appdataroot,
];
$storage = new LocalRootStorage($arguments);
$mount = new MountPoint($storage, $folderName, $arguments);
\OC::$server->getMountManager()->addMount($mount);

return $rootFolder->get($folderName);
}
return $rootFolder;
});
}

private function getAppDataFolderName() {
Expand Down
1 change: 1 addition & 0 deletions lib/private/SystemConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SystemConfig {
protected $sensitiveValues = [
'instanceid' => true,
'datadirectory' => true,
'appdataroot' => true,
'dbname' => true,
'dbhost' => true,
'dbpassword' => true,
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/Files/AppData/AppDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ protected function setUp(): void {
->method('getValue')
->with('instanceid', null)
->willReturn('iid');

$this->systemConfig->expects($this->any())
->method('getValue')
->with('appdataroot', null)
->willReturn('/path');
}

private function setupAppFolder() {
Expand Down

0 comments on commit 145000e

Please sign in to comment.