Skip to content

Commit

Permalink
Merge writable temporary space check with the s3 one, and improve
Browse files Browse the repository at this point in the history
It will now show available space and path of both PHP and Nextcloud
 temporary directories if they differ.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Jan 25, 2024
1 parent ccbc5fc commit 9add64f
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 87 deletions.
2 changes: 1 addition & 1 deletion apps/settings/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => $baseDir . '/../lib/SetupChecks/ReadOnlyConfig.php',
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => $baseDir . '/../lib/SetupChecks/SupportedDatabase.php',
'OCA\\Settings\\SetupChecks\\SystemIs64bit' => $baseDir . '/../lib/SetupChecks/SystemIs64bit.php',
'OCA\\Settings\\SetupChecks\\TempSpaceAvailableIfS3PrimaryStorage' => $baseDir . '/../lib/SetupChecks/TempSpaceAvailableIfS3PrimaryStorage.php',
'OCA\\Settings\\SetupChecks\\TempSpaceAvailable' => $baseDir . '/../lib/SetupChecks/TempSpaceAvailable.php',
'OCA\\Settings\\SetupChecks\\TransactionIsolation' => $baseDir . '/../lib/SetupChecks/TransactionIsolation.php',
'OCA\\Settings\\UserMigration\\AccountMigrator' => $baseDir . '/../lib/UserMigration/AccountMigrator.php',
'OCA\\Settings\\UserMigration\\AccountMigratorException' => $baseDir . '/../lib/UserMigration/AccountMigratorException.php',
Expand Down
2 changes: 1 addition & 1 deletion apps/settings/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => __DIR__ . '/..' . '/../lib/SetupChecks/ReadOnlyConfig.php',
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => __DIR__ . '/..' . '/../lib/SetupChecks/SupportedDatabase.php',
'OCA\\Settings\\SetupChecks\\SystemIs64bit' => __DIR__ . '/..' . '/../lib/SetupChecks/SystemIs64bit.php',
'OCA\\Settings\\SetupChecks\\TempSpaceAvailableIfS3PrimaryStorage' => __DIR__ . '/..' . '/../lib/SetupChecks/TempSpaceAvailableIfS3PrimaryStorage.php',
'OCA\\Settings\\SetupChecks\\TempSpaceAvailable' => __DIR__ . '/..' . '/../lib/SetupChecks/TempSpaceAvailable.php',
'OCA\\Settings\\SetupChecks\\TransactionIsolation' => __DIR__ . '/..' . '/../lib/SetupChecks/TransactionIsolation.php',
'OCA\\Settings\\UserMigration\\AccountMigrator' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigrator.php',
'OCA\\Settings\\UserMigration\\AccountMigratorException' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigratorException.php',
Expand Down
4 changes: 2 additions & 2 deletions apps/settings/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
use OCA\Settings\SetupChecks\ReadOnlyConfig;
use OCA\Settings\SetupChecks\SupportedDatabase;
use OCA\Settings\SetupChecks\SystemIs64bit;
use OCA\Settings\SetupChecks\TempSpaceAvailableIfS3PrimaryStorage;
use OCA\Settings\SetupChecks\TempSpaceAvailable;
use OCA\Settings\SetupChecks\TransactionIsolation;
use OCA\Settings\UserMigration\AccountMigrator;
use OCA\Settings\WellKnown\ChangePasswordHandler;
Expand Down Expand Up @@ -207,7 +207,7 @@ public function register(IRegistrationContext $context): void {
$context->registerSetupCheck(ReadOnlyConfig::class);
$context->registerSetupCheck(SupportedDatabase::class);
$context->registerSetupCheck(SystemIs64bit::class);
$context->registerSetupCheck(TempSpaceAvailableIfS3PrimaryStorage::class);
$context->registerSetupCheck(TempSpaceAvailable::class);
$context->registerSetupCheck(TransactionIsolation::class);

$context->registerUserMigrator(AccountMigrator::class);
Expand Down
16 changes: 0 additions & 16 deletions apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\ITempManager;
use OCP\IURLGenerator;
use OCP\Notification\IManager;
use OCP\SetupCheck\ISetupCheckManager;
Expand All @@ -73,8 +72,6 @@ class CheckSetupController extends Controller {
private $checker;
/** @var LoggerInterface */
private $logger;
/** @var ITempManager */
private $tempManager;
/** @var IManager */
private $manager;
private ISetupCheckManager $setupCheckManager;
Expand All @@ -86,7 +83,6 @@ public function __construct($AppName,
IL10N $l10n,
Checker $checker,
LoggerInterface $logger,
ITempManager $tempManager,
IManager $manager,
ISetupCheckManager $setupCheckManager,
) {
Expand All @@ -96,7 +92,6 @@ public function __construct($AppName,
$this->l10n = $l10n;
$this->checker = $checker;
$this->logger = $logger;
$this->tempManager = $tempManager;
$this->manager = $manager;
$this->setupCheckManager = $setupCheckManager;
}
Expand Down Expand Up @@ -192,16 +187,6 @@ public function getFailedIntegrityCheckFiles(): DataDisplayResponse {
);
}

private function isTemporaryDirectoryWritable(): bool {
try {
if (!empty($this->tempManager->getTempBaseDir())) {
return true;
}
} catch (\Exception $e) {
}
return false;
}

/**
* @return DataResponse
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
Expand All @@ -212,7 +197,6 @@ public function check() {
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
'temporaryDirectoryWritable' => $this->isTemporaryDirectoryWritable(),
'generic' => $this->setupCheckManager->runAll(),
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@

use OCP\IConfig;
use OCP\IL10N;
use OCP\ITempManager;
use OCP\IURLGenerator;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

class TempSpaceAvailableIfS3PrimaryStorage implements ISetupCheck {
class TempSpaceAvailable implements ISetupCheck {
public function __construct(
private IL10N $l10n,
private IConfig $config,
private IURLGenerator $urlGenerator,
private ITempManager $tempManager,
) {
}

Expand All @@ -47,46 +49,77 @@ public function getCategory(): string {
return 'system';
}

public function run(): SetupResult {
private function isPrimaryStorageS3(): bool {
$objectStore = $this->config->getSystemValue('objectstore', null);
$objectStoreMultibucket = $this->config->getSystemValue('objectstore_multibucket', null);

// TODO we should check and display temp space available even if not s3
if (!isset($objectStoreMultibucket) && !isset($objectStore)) {
return SetupResult::success($this->l10n->t('This instance does not use an S3 based object store as primary storage'));
return false;
}

if (isset($objectStoreMultibucket['class']) && $objectStoreMultibucket['class'] !== 'OC\\Files\\ObjectStore\\S3') {
return SetupResult::success($this->l10n->t('This instance does not use an S3 based object store as primary storage'));
return false;
}

if (isset($objectStore['class']) && $objectStore['class'] !== 'OC\\Files\\ObjectStore\\S3') {
return SetupResult::success($this->l10n->t('This instance does not use an S3 based object store as primary storage'));
return false;
}

return true;
}

public function run(): SetupResult {
$phpTempPath = sys_get_temp_dir();
$nextcloudTempPath = '';
try {
$nextcloudTempPath = $this->tempManager->getTempBaseDir();
} catch (\Exception $e) {
}

if (empty($nextcloudTempPath)) {
return SetupResult::error('The temporary directory of this instance points to an either non-existing or non-writable directory.');
}

$tempPath = sys_get_temp_dir();
if (!is_dir($tempPath)) {
return SetupResult::error($this->l10n->t('Error while checking the temporary PHP path - it was not properly set to a directory. Returned value: %s', [$tempPath]));
if (!is_dir($phpTempPath)) {
return SetupResult::error($this->l10n->t('Error while checking the temporary PHP path - it was not properly set to a directory. Returned value: %s', [$phpTempPath]));
}
$freeSpaceInTemp = function_exists('disk_free_space') ? disk_free_space($tempPath) : false;

$freeSpaceInTemp = function_exists('disk_free_space') ? disk_free_space($phpTempPath) : false;
if ($freeSpaceInTemp === false) {
return SetupResult::error($this->l10n->t('Error while checking the available disk space of temporary PHP path or no free disk space returned. Temporary path: %s', [$tempPath]));
return SetupResult::error($this->l10n->t('Error while checking the available disk space of temporary PHP path or no free disk space returned. Temporary path: %s', [$phpTempPath]));
}

/** Build details data about temporary directory, either one or two of them */
$freeSpaceInTempInGB = $freeSpaceInTemp / 1024 / 1024 / 1024;
$spaceDetail = $this->l10n->t('- %.1f GiB available in %s (PHP temporary directory)', [round($freeSpaceInTempInGB, 1),$phpTempPath]);
if ($nextcloudTempPath !== $phpTempPath) {
$freeSpaceInNextcloudTemp = function_exists('disk_free_space') ? disk_free_space($nextcloudTempPath) : false;
if ($freeSpaceInNextcloudTemp === false) {
return SetupResult::error($this->l10n->t('Error while checking the available disk space of temporary PHP path or no free disk space returned. Temporary path: %s', [$nextcloudTempPath]));
}
$freeSpaceInNextcloudTempInGB = $freeSpaceInNextcloudTemp / 1024 / 1024 / 1024;
$spaceDetail .= "\n".$this->l10n->t('- %.1f GiB available in %s (Nextcloud temporary directory)', [round($freeSpaceInNextcloudTempInGB, 1),$nextcloudTempPath]);
}

if (!$this->isPrimaryStorageS3()) {
return SetupResult::success(
$this->l10n->t("Temporary directory is correctly configured:\n%s", [$spaceDetail])
);
}

if ($freeSpaceInTempInGB > 50) {
return SetupResult::success(
$this->l10n->t(
"This instance uses an S3 based object store as primary storage, and has enough space in the temporary directory.\nAvailable: %.1f GiB\nPath: %s",
[round($freeSpaceInTempInGB, 1),$tempPath]
"This instance uses an S3 based object store as primary storage, and has enough space in the temporary directory.\n%s",
[$spaceDetail]
)
);
}

return SetupResult::warning(
$this->l10n->t(
"This instance uses an S3 based object store as primary storage. The uploaded files are stored temporarily on the server and thus it is recommended to have 50 GiB of free space available in the temp directory of PHP. To improve this please change the temporary directory in the php.ini or make more space available in that path. \nChecking the available space in the temporary path resulted in %.1f GiB instead of the recommended 50 GiB. Path: %s",
[round($freeSpaceInTempInGB, 1),$tempPath]
[round($freeSpaceInTempInGB, 1),$phpTempPath]
)
);
}
Expand Down
6 changes: 0 additions & 6 deletions apps/settings/tests/Controller/CheckSetupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\ITempManager;
use OCP\IURLGenerator;
use OCP\Notification\IManager;
use OCP\SetupCheck\ISetupCheckManager;
Expand Down Expand Up @@ -72,8 +71,6 @@ class CheckSetupControllerTest extends TestCase {
private $logger;
/** @var Checker|\PHPUnit\Framework\MockObject\MockObject */
private $checker;
/** @var ITempManager|\PHPUnit\Framework\MockObject\MockObject */
private $tempManager;
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
private $notificationManager;
/** @var ISetupCheckManager|MockObject */
Expand All @@ -98,7 +95,6 @@ protected function setUp(): void {
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
->disableOriginalConstructor()->getMock();
$this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
$this->tempManager = $this->getMockBuilder(ITempManager::class)->getMock();
$this->notificationManager = $this->getMockBuilder(IManager::class)->getMock();
$this->setupCheckManager = $this->createMock(ISetupCheckManager::class);
$this->checkSetupController = $this->getMockBuilder(CheckSetupController::class)
Expand All @@ -110,7 +106,6 @@ protected function setUp(): void {
$this->l10n,
$this->checker,
$this->logger,
$this->tempManager,
$this->notificationManager,
$this->setupCheckManager,
])
Expand Down Expand Up @@ -176,7 +171,6 @@ public function testCheck() {
'reverseProxyDocs' => 'reverse-proxy-doc-link',
'reverseProxyGeneratedURL' => 'https://server/index.php',
'isFairUseOfFreePushService' => false,
'temporaryDirectoryWritable' => false,
'generic' => [],
]
);
Expand Down
6 changes: 0 additions & 6 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,6 @@
});
}

if (!data.temporaryDirectoryWritable) {
messages.push({
msg: t('core', 'The temporary directory of this instance points to an either non-existing or non-writable directory.'),
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
})
}
if (window.location.protocol === 'https:' && data.reverseProxyGeneratedURL.split('/')[0] !== 'https:') {
messages.push({
msg: t('core', 'You are accessing your instance over a secure connection, however your instance is generating insecure URLs. This most likely means that you are behind a reverse proxy and the overwrite config variables are not set correctly. Please read {linkstart}the documentation page about this ↗{linkend}.')
Expand Down
41 changes: 0 additions & 41 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ describe('OC.SetupChecks tests', function() {
JSON.stringify({
isFairUseOfFreePushService: true,
reverseProxyGeneratedURL: 'https://server',
temporaryDirectoryWritable: true,
generic: {
network: {
"Internet connectivity": {
Expand Down Expand Up @@ -260,7 +259,6 @@ describe('OC.SetupChecks tests', function() {
JSON.stringify({
isFairUseOfFreePushService: true,
reverseProxyGeneratedURL: 'https://server',
temporaryDirectoryWritable: true,
generic: {
network: {
"Internet connectivity": {
Expand Down Expand Up @@ -295,7 +293,6 @@ describe('OC.SetupChecks tests', function() {
JSON.stringify({
isFairUseOfFreePushService: true,
reverseProxyGeneratedURL: 'https://server',
temporaryDirectoryWritable: true,
generic: {
network: {
"Internet connectivity": {
Expand Down Expand Up @@ -331,7 +328,6 @@ describe('OC.SetupChecks tests', function() {
isFairUseOfFreePushService: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
reverseProxyGeneratedURL: 'https://server',
temporaryDirectoryWritable: true,
generic: {
network: {
"Internet connectivity": {
Expand Down Expand Up @@ -396,7 +392,6 @@ describe('OC.SetupChecks tests', function() {
JSON.stringify({
isFairUseOfFreePushService: true,
reverseProxyGeneratedURL: 'https://server',
temporaryDirectoryWritable: true,
generic: {
network: {
"Internet connectivity": {
Expand Down Expand Up @@ -441,7 +436,6 @@ describe('OC.SetupChecks tests', function() {
isFairUseOfFreePushService: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
reverseProxyGeneratedURL: 'http://server',
temporaryDirectoryWritable: true,
generic: {
network: {
"Internet connectivity": {
Expand Down Expand Up @@ -475,7 +469,6 @@ describe('OC.SetupChecks tests', function() {
isFairUseOfFreePushService: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
reverseProxyGeneratedURL: 'http://server',
temporaryDirectoryWritable: true,
generic: {
network: {
"Internet connectivity": {
Expand Down Expand Up @@ -505,7 +498,6 @@ describe('OC.SetupChecks tests', function() {
JSON.stringify({
isFairUseOfFreePushService: true,
reverseProxyGeneratedURL: 'https://server',
temporaryDirectoryWritable: true,
generic: {
network: {
"Internet connectivity": {
Expand Down Expand Up @@ -533,39 +525,6 @@ describe('OC.SetupChecks tests', function() {
done();
});
});

it('should return an info if the temporary directory is either non-existent or non-writable', function(done) {
var async = OC.SetupChecks.checkSetup();

suite.server.requests[0].respond(
200,
{
'Content-Type': 'application/json',
},
JSON.stringify({
isFairUseOfFreePushService: true,
reverseProxyGeneratedURL: 'https://server',
temporaryDirectoryWritable: false,
generic: {
network: {
"Internet connectivity": {
severity: "success",
description: null,
linkToDoc: null
}
},
},
})
);

async.done(function( data, s, x ){
expect(data).toEqual([{
msg: 'The temporary directory of this instance points to an either non-existing or non-writable directory.',
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
}]);
done();
});
});
});

describe('checkGeneric', function() {
Expand Down

0 comments on commit 9add64f

Please sign in to comment.