From 4c522f0f654ccbd1f48935a7a99324600f0a1c16 Mon Sep 17 00:00:00 2001 From: Simon L Date: Thu, 16 Nov 2023 16:06:44 +0100 Subject: [PATCH 1/2] do not write htaccess file if disk space is too low Signed-off-by: Simon L --- lib/private/Setup.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/private/Setup.php b/lib/private/Setup.php index e763b6d39c1d6..4fea5d72591f0 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -560,6 +560,14 @@ public static function updateHtaccess() { } if ($content !== '') { + // Never write file back if disk space should be too low + if (function_exists('disk_free_space')) { + $df = disk_free_space(\OC::$SERVERROOT); + $size = strlen($content) + 10240; + if ($df !== false && $df < (float)$size) { + throw new \Exception(\OC::$SERVERROOT . " does not have enough space for writing the htaccess file! Not writing it back!"); + } + } //suppress errors in case we don't have permissions for it return (bool)@file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent . $content . "\n"); } From 3f6caa46f34a1575dc332f9ce1a2edaba99a1b11 Mon Sep 17 00:00:00 2001 From: Simon L Date: Fri, 17 Nov 2023 11:32:31 +0100 Subject: [PATCH 2/2] document error Signed-off-by: Simon L --- core/Command/Maintenance/UpdateHtaccess.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Command/Maintenance/UpdateHtaccess.php b/core/Command/Maintenance/UpdateHtaccess.php index 67c6db22b21ca..9243567afb4b7 100644 --- a/core/Command/Maintenance/UpdateHtaccess.php +++ b/core/Command/Maintenance/UpdateHtaccess.php @@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('.htaccess has been updated'); return 0; } else { - $output->writeln('Error updating .htaccess file, not enough permissions or "overwrite.cli.url" set to an invalid URL?'); + $output->writeln('Error updating .htaccess file, not enough permissions, not enough free space or "overwrite.cli.url" set to an invalid URL?'); return 1; } }