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

do not write htaccess file if disk space is too low #41544

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Changes from 1 commit
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
Next Next commit
do not write htaccess file if disk space is too low
Signed-off-by: Simon L <szaimen@e.mail.de>
  • Loading branch information
szaimen committed Nov 17, 2023
commit 4c522f0f654ccbd1f48935a7a99324600f0a1c16
8 changes: 8 additions & 0 deletions lib/private/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
szaimen marked this conversation as resolved.
Show resolved Hide resolved
}
}
//suppress errors in case we don't have permissions for it
return (bool)@file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent . $content . "\n");
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can also check if all bytes have been written. Should be something like this:

Suggested change
return (bool)@file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent . $content . "\n");
$fullContent = $htaccessContent . $content . "\n";
return @file_put_contents($setupHelper->pathToHtaccess(), $$fullContent) === strlen($fullContent);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not going to help here. The prpblem is that file_pu_content truncates the file if there is not enough space which should never happen as the file is very important to work...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We had the same prpblem with config.php before and fixed in in the same way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's another security in case something happen during the copy.
The file will already be erased, but at least you'll have the info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see.

}
Expand Down