-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Improve quota handling #39895
Improve quota handling #39895
Conversation
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes. |
021d6a3
to
c13480e
Compare
Problem with the tests is in https://github.com/owncloud/core/pull/39895/files#diff-b89bc6bd7d5336d68032bb5a5c1f309df16f27173f9f58d9f338ec495d3f951bL145-R160 When overwriting a shared file by the sharee, the part file is written into the sharee's storage and then moved to the share. If there is a limiting quota in the sharee, the part file can't be written even though the sharer has enough free space. Challenges for a proper fix are:
Worst case, we might need to revert that piece. The fix for the original issue should still work since it's applied in the Sabre connector (DAV interface) |
I added test scenarios to check "COPY" of a file from a received share into a user's own storage. Those fail on current master, and pass with this PR, so that is good. There are already scenarios for "MOVE" and they pass, so there is no regression for that. I also added some more scenarios for the case where the file is zero bytes (empty). Those have always been allowed, and are still allowed. Users with zero quota can create folders and empty files. |
The list of cases to be checked, assuming user1 has 1KB of quota, user2 1GB of quota and the target file is 10MB:
There are some additional variations using a move operation instead of a copy, uploading whole folders (not sure how it will behave if only some of the files in the uploaded folder fit the quota), etc. Note the behavior is different for shared files and shared folders. |
Kudos, SonarCloud Quality Gate passed! |
*/ | ||
private function getExpectedContentLength($data) { | ||
$expected = -1; | ||
if (isset($_SERVER['CONTENT_LENGTH'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
working on global var is kind of spooky - isn't there a way to get access to the sabre request object or at least the oc request object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That piece was moved. I've just added additional ways to try to figure out the content length because I think in case of COPY requests the error message showed a -1 as expected size.
It's only used for the error message, so it's OK.
// We'll assume the "beforeMethod:*" is being processed, so we'll process our "handleBeforeCopy" | ||
// right away. | ||
if ($server->httpRequest->getMethod() === 'COPY') { | ||
$this->handleBeforeCopy($server->httpRequest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be called super early (within ::initialize) - if this is intended I am okay with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's intended until we find a better way to set it up.
@jvillafanez could you fix the conflicts? |
This is waiting for sabre-io/dav#1396 so there will be some code changes. |
should we wait until sabre/dav has an official release with the changes in sabre-io/dav#1396 ? We'd need to pin the version in the composer.json file |
info, I have requested @phil-davis if he could do a new release of sabre-io/dav as he did this last time, just linking to the issue: sabre-io/dav#1406 |
c71341f
to
d1f35d5
Compare
Rebased and code updated to use sabre 4.4 for new events. Note that there have been conflicts in "tests/acceptance/features/apiMain/quota.feature" which might need a second look in case there is anything missing. |
💥 Acceptance tests pipeline cliDbConversion-sqlite-php7.4 failed. The build has been cancelled. |
* In case there are problems writing the contents of the file, try to figure out the size of the content in several ways in order to provide a more meaningful message * Ensure the locks are properly released in case an error happens * Handle quota while copying files. In addition, take into account the space used by the file we're trying to overwrite (in case there is already a file there) * Part files will also be considered for quota while they're being uploaded
d1f35d5
to
064efe7
Compare
@phil-davis could you check the acceptance tests? I think we can remove the ones in "tests/acceptance/features/apiMain/quotaOc10Issue40140.feature" and remove or adjust some "skipOnOcV10" from the "tests/acceptance/features/apiMain/quota.feature" |
Acceptance tests have been sorted out and are passing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are all passing, so there is no obvious regression. And the new/changed tests demonstrate that quota checks work better for the COPY case.
Needs final developer review.
Kudos, SonarCloud Quality Gate passed! |
@janackermann @JammingBen mind to take a look on for a final approval, would be great to go into 10.11 - many thanks |
figure out the size of the content in several ways in order to provide a
more meaningful message
space used by the file we're trying to overwrite (in case there is
already a file there)
uploaded
Description
Copying a received shared file out of the share could go over the quota limit imposed by the admin. This PR fixes that issue and other related ones
Related Issue
https://github.com/owncloud/enterprise/issues/5023
Fixes #40140
Motivation and Context
Total file size should never be over the quota
How Has This Been Tested?
Manually tested
user1 must receive an "Insufficient Storage" error and the file mustn't have been copied.
Some other variations have been tested also manually:
Types of changes
Checklist: