Skip to content

Commit

Permalink
Allow configuring the location of the appdata folder
Browse files Browse the repository at this point in the history
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

update method to check mount points and determine if cache scanner should run

simplify method to check mount points

fix unit test

add missing line; cleanup lint

perform lint cleanup

run cs-fixer

replace deprecated methods; fix invalid value for `$mountPoint` in `LocalRootScanner:shouldScanPath`

rename appdataroot to appdatadirectory

remove inaccurate language from `config.sample.php`

Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com>
  • Loading branch information
summersab committed Sep 7, 2023
1 parent eb55101 commit 96681f1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
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) {
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);
$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_');
}
}
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

0 comments on commit 96681f1

Please sign in to comment.