Skip to content

fix(files): account for replaced files in quota checks - #65876

Open
joshtrichards wants to merge 4 commits into
masterfrom
jtr/fix-QuotaWrapper
Open

joshtrichards wants to merge 4 commits into
masterfrom
jtr/fix-QuotaWrapper

Conversation

@joshtrichards

Copy link
Copy Markdown
Member

Summary

  • Allow write and copy operations that exactly fit the available quota.
  • Credit the size of eligible existing targets in quota checks when replacing files.
  • Add regression coverage for exact-fit operations and replacement credit.

Preserves conservative physical free-space checks: replacement credit applies only to account quota usage.

For moves, credits the existing destination but conservatively continues requiring space for the full source, since the check cannot currently establish whether the source is already included in quota usage.

Follow-up

Quota-scope enforcement appears inconsistent across mutator operations for destinations outside files/, including internal trash and version paths. I haven't found a convincing reason for applying the account quota differently depending on the operation:

  • shouldApplyQuota() documents that quota applies to files under files/, not metadata, trash, or other paths. fopen() and mkdir() honor that distinction, while touch() applies its zero-space rejection unconditionally. The same scope question applies to file_put_contents(), copy(), copyFromStorage(), and moveFromStorage().
  • writeStream() scope-gates its zero-space rejection, but when a size is supplied, it still compares that size against quota-limited free space for paths outside files/.

The changes introduced by this PR should make that easier to address separately. I considered including scope-policy changes here, but reverted them part-way through in order to keep this PR focused and avoid expanding the regression surface of the current fix.

A follow-up needs further call-site and test-coverage auditing, particularly around trash/version operations, restores, and physical-storage failures. If the differences are intentional, it should instead document why particular operations are exceptions.

Related:

TODO

  • Backport? Not sure.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Use inclusive size checks when comparing a write or copy against the remaining quota. This allows an operation whose size equals the available space, while still rejecting operations that exceed it.

Signed-off-by: Josh <josh.t.richards@gmail.com>
Add regression tests for writes and transfers whose size exactly matches the remaining quota.

Exercise quota-limited streams with chunked writes, and test writeStream with both known and unknown input sizes.

Assisted-by: Copilot:gpt-6-luna

Signed-off-by: Josh <josh.t.richards@gmail.com>
When an operation replaces an existing file with a known size inside the quota scope, credit that size against quota usage. Do not credit it against physical free space, which may not be reclaimed immediately by every storage backend.

For moves, credit the existing destination but continue requiring space for the full source, since whether the source is already included in the quota total may be unknown.

Signed-off-by: Josh <josh.t.richards@gmail.com>
Verify that quota checks credit known existing targets for writes, copies, and moves.

Cover the conservative move behavior when the source is already included in quota usage.

Assisted-by: Copilot:gpt-6-luna

Signed-off-by: Josh <josh.t.richards@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full quota prevents exact-fit uploads and also downloading existing files

2 participants