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

Allow configuring the location of the appdata_[instanceid] folder #36337

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
9 changes: 9 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1924,6 +1924,15 @@
*/
'updatedirectory' => '',

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

/**
* Blacklist a specific file or files and disallow the upload of files
* with this name. ``.htaccess`` is blocked by default.
Expand Down
24 changes: 23 additions & 1 deletion lib/private/Files/AppData/AppData.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
namespace OC\Files\AppData;

use OCP\Cache\CappedMemoryCache;
use OC\Files\Filesystem;
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 +59,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) {
Copy link
Member

Choose a reason for hiding this comment

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

Why are you creating a new LazyRoot?

if ($appdatadirectory = $systemConfig->getValue('appdatadirectory', null)) {
$instanceId = $systemConfig->getValue('instanceid', null);
if ($instanceId === null) {
throw new \RuntimeException('no instance id!');
}

$folderName = 'appdata_' . $instanceId;

$arguments = [
'datadir' => $appdatadirectory,
];
$storage = new LocalRootStorage($arguments);
Copy link
Member

Choose a reason for hiding this comment

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

This should just be Local not LocalRootStorage

$mount = new MountPoint($storage, $folderName, $arguments);
Filesystem::getMountManager()->addMount($mount);
}
return $rootFolder;
});
}

private function getAppDataFolderName() {
Expand Down
8 changes: 7 additions & 1 deletion lib/private/Files/Cache/LocalRootScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*/
namespace OC\Files\Cache;

use OC\Files\Filesystem;

class LocalRootScanner extends Scanner {
public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
if ($this->shouldScanPath($file)) {
Expand All @@ -43,7 +45,11 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $loc
}

private function shouldScanPath(string $path): bool {
$storageId = $this->storage->getId();
$mount = Filesystem::getMountManager()->findByStorageId($storageId);
$mountPoint = sizeof($mount) == 1 ? $mount[0]->getMountPoint() : "null";

$path = trim($path, '/');
return $path === '' || str_starts_with($path, 'appdata_') || str_starts_with($path, '__groupfolders');
return $path === '' || str_starts_with($path, 'appdata_') || str_starts_with($path, '__groupfolders') || str_starts_with($mountPoint, '/appdata_');
Comment on lines +48 to +53
Copy link
Member

Choose a reason for hiding this comment

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

If you want to stop the scanner from touching the new appdata mountpoint, you can instead create a storage with a "noop" scanner.

}
}
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,
'appdatadirectory' => true,
'dbname' => true,
'dbhost' => true,
'dbpassword' => true,
Expand Down
6 changes: 4 additions & 2 deletions tests/lib/Files/AppData/AppDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ protected function setUp(): void {

$this->systemConfig->expects($this->any())
->method('getValue')
->with('instanceid', null)
->willReturn('iid');
->willReturnMap([
['instanceid', null, 'iid'],
['appdatadirectory', null, '/path'],
]);
}

private function setupAppFolder() {
Expand Down
Loading