Skip to content

Files Recycle Bin Follow Ups PR Review

Ed Mozley edited this page Nov 28, 2026 · 1 revision

Files recycle bin follow-ups - PR review

PR #431 by @cloudcogsio Β· Issue #421 Β· Verdict: merge + fix Β· 5.12.0

Four things @cloudcogsio noticed in the recycle bin after it shipped, raised in #421 first and then sent as one commit each. User page: Files Β§ Deleting and the recycle bin. How it works: Recycle bin - Developer Guide.

What you saw

Before After
Storage refuses to delete some bytes (a bucket policy, a read-only folder) Retried every hour, for ever, with nothing to say it was stuck Tried every run for 24 refusals, then once a day, logged once. The job shows as partly failing and the Recycle bin settings tab shows the count. Goes by itself once storage is fixed
Delete key in the recycle bin with some items you cannot delete permanently Those were skipped without a word - with none deletable, nothing happened at all The confirm says how many stay; with none deletable, a notice says so
The bin's size on the settings tab Every files_versions row loaded into PHP and walked One SQL query

βœ… What was good - keep it this way

What Why it matters
Raised in an issue first, one commit per item, with tests Each change could be agreed, and read, on its own
The CTE is FilesAcl::tree()'s rule exactly - a folder is live only through a live parent - and a test compares it with the old walk, a live file in a deleted folder and a deleted copy sharing a live file's bytes included The new query is proven equal, not just believed
Only refusals count; an outage leaves attempts alone - one upsert, attempts + VALUES(attempts) with 0 or 1 An outage never pushes a key into the slow lane
Never dropped, logged exactly once when it moves to daily Nothing is lost; the log is not flooded
refused counted after the loop, from the table Right even when the deadline cut the run short
levels() and levelsIncludingDeleted() share one grant query Same SQL, same cache; no access result changes
A test that runs before Database Verification (the table renamed away and back in finally) and one over HTTP (410 in the bin, 302 after restore) The upgrade path and the real endpoint are both covered

πŸ”§ What was added and fixed when merging

1. On S3, a refusal was still counted as an outage 🟠

The whole point of item 1 - and the case #421 described, "a 403 from a bucket policy" - did not work on S3. The S3 driver threw the same StorageUnavailable for every non-2xx answer, 403 included, and filesPurgeBytesIfUnused() turned every StorageUnavailable into unavailable. So attempts never moved and the key was retried every hour, for ever. The PR's tests modelled a refusal only with a read-only local folder, so they could not see it.

Now the driver throws StorageRefused for a 4xx other than 404, 408 and 429, unless the error code says the credentials are wrong; filesPurgeBytesIfUnused() and FilesRecycleService::purgeBytes() map it to failed, which the queue counts.

// includes/storage/driver.php
class StorageRefused extends StorageUnavailable {}

// includes/storage/s3_driver.php
$credentials = ['InvalidAccessKeyId', 'SignatureDoesNotMatch', 'ExpiredToken', 'InvalidToken', 'RequestTimeTooSkewed', 'AuthorizationHeaderMalformed'];
if ($status >= 400 && $status < 500 && !in_array($status, [404, 408, 429], true) && !in_array($code, $credentials, true)) {
    throw new StorageRefused($this->errorText($status, $buffer, $code), 0);
}
  • Why a subclass: every caller that only knows "unavailable" still catches it and still answers 503. Only the purge queue asks the difference. A TRAP: comment says so.
  • Why bad credentials are not a refusal: they are an outage of the whole store. Counted as refusals, every key would move to once a day after 24 hours, and fixing the keys would take up to a day to clear the queue.
  • Test: tests/storage-s3-refused.php runs S3Driver::delete() against a stand-in S3 that answers 403 AccessDenied, 409, 403 InvalidAccessKeyId (the control), 403 SignatureDoesNotMatch, 429, 503, 404 and 204.

2. A lost cache-buster 🟑

The branch started on 5.9.0 and had 5.10.1 merged into it; that merge kept main's files-desktop.js?v=21 and lost the PR's bump, so browsers would have kept the old script and the Delete key would have gone on skipping items silently until a hard refresh. Now v=22.

Smaller

  • "Once a day" is 24 hours less ten minutes. The hourly job starts a few seconds either side of the hour; INTERVAL 24 HOUR exactly would slip a run and retry every 25 hours.
  • The pending count's wording said "because storage could not be reached" - it now also holds keys refused fewer than 24 times. Now Stored files waiting to be removed (tried again every hour).
  • tests/files-recycle-bin.php on Windows. Its refusal block makes a folder read-only with chmod 0555, which Windows ignores, so it reported eight failures that were the test's. It now proves the folder refuses first, and otherwise says SKIP and why.

Left as it is

  • Keys already in the queue at upgrade. Before this PR attempts counted outages too, so a key that sat through a day-long outage on 5.11.0 is read as refused after the upgrade and tried daily. Rare, and it clears itself the first time storage lets it go - not worth a migration. In the developer guide's traps.
  • An unmounted share looks like success (not this PR's): LocalDriver::delete() returns early when the file is not there, so with the storage root's share unmounted every purge reports deleted and the queue row goes while the bytes stay. A separate follow-up.

πŸ§ͺ What was checked

Test Result
tests/files-recycle-bin.php (the PR's, extended) 69 passed; refusal block skipped on Windows (see above); S3 block needs a bucket
tests/files-recycle-held.php 34 passed
tests/files-recycle-before-verification.php (new) 9 passed
tests/files-recycle-links-http.php (new) 6 passed
tests/storage-s3-refused.php (new, the fix) 10 passed

All on a disposable test install with Database Verification run first.


See also: Files Β· Recycle bin - PR review Β· Recycle bin - Developer Guide Β· Bugs resolved

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally