From fb1963a2f3c687c834d4d8c9418011cddef33082 Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 22 Dec 2025 12:06:49 +0100 Subject: [PATCH 1/2] fix: create .htaccess file in case it doesn't exist yet Currently, the updateHtaccess() function can't deal with a missing .htaccess file, it assumes at least an empty .htaccess file. In some cases, the file may be missing though, and this commit adds functionality for creating it when this edgecase occurs. Signed-off-by: Marc --- lib/private/Setup.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 5f91dc1069261..f97e945054556 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -556,6 +556,15 @@ public static function updateHtaccess(): bool { $setupHelper = Server::get(\OC\Setup::class); + // Note: The .htaccess file also needs to exist, otherwise `is_writable()` + // will return false, even though the file could be written. + // This function writes the .htaccess file in that case. + if (!file_exists($setupHelper->pathToHtaccess())) { + if (!touch($setupHelper->pathToHtaccess())) { + return false; + } + } + if (!is_writable($setupHelper->pathToHtaccess())) { return false; } From c9a168b0564830fb2d43e265ecc160063111b5ca Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 22 Dec 2025 12:18:06 +0100 Subject: [PATCH 2/2] fix: changed wording of error for occ maintenance:update:htaccess This adds a hint to the error message that file creation may also have failed. Signed-off-by: Marc --- 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 eeff3bf8c62de..625c028d57d77 100644 --- a/core/Command/Maintenance/UpdateHtaccess.php +++ b/core/Command/Maintenance/UpdateHtaccess.php @@ -24,7 +24,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, not enough free space or "overwrite.cli.url" set to an invalid URL?'); + $output->writeln('Error updating (or creating) .htaccess file, not enough permissions, not enough free space or "overwrite.cli.url" set to an invalid URL?'); return 1; } }