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>

fix caching issue preventing files from being written directly to mount point
  • Loading branch information
summersab committed Feb 9, 2023
1 parent 75d7203 commit 783ad06
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
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
23 changes: 22 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,28 @@ 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;
});
}

private function getAppDataFolderName() {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/LocalRootScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc

private function shouldScanPath(string $path): bool {
$path = trim($path, '/');
return $path === '' || strpos($path, 'appdata_') === 0 || strpos($path, '__groupfolders') === 0;
return $path === '' || strpos($path, 'appdata_') === 0 || strpos($path, '__groupfolders') === 0 || strpos($this->storage->getMountPoint(), '/appdata_') === 0;
}
}
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 783ad06

Please sign in to comment.