Repository navigation
Conversation
… separator S3::delete() accepted a $recursive flag and ignored it, so a caller deleting a tree left every object behind. The listing prefix now ends with a separator so a sibling with a shared name prefix is not deleted.
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
|
| if ($recursive && $path !== '') { | ||
| $this->deleteByPrefix($path); | ||
| } |
There was a problem hiding this comment.
S3 DeleteObjects can return HTTP 200 while reporting per-key failures in its XML body. deleteByPrefix() currently ignores that response and returns true, so this new recursive path can leave objects behind yet continue to the exact-key DELETE and report success. Inspect the bulk-delete result and surface any <Error> entries before treating the recursive delete as successful.
|
Storage now lives in |
|
Thanks, re-opened as appwrite/appwrite#13961 against |
Problem
Device::delete(string $path, bool $recursive = false)is implemented byLocal, which walks the tree when$recursiveis true, and byS3, which declares the parameter and never reads it.S3::delete($path, true)sends oneDELETEfor the directory key. S3 has no directories, so that request removes nothing and returns success, and every object under the path stays in the bucket.Appwrite deletes a project's files this way,
delete($device->getRoot(), true)on the files, sites, functions, builds and cache devices, so on any S3 device a deleted project's objects are left behind, AWS included. Reported in appwrite/appwrite#13808, whose main symptom is a separate Appwrite-side configuration problem; this is the library half.A second, quieter problem in the same area:
deletePath()lists with"{root}/{path}"as the prefix, with no trailing separator.deletePath('app-1')matchesapp-12/...too, so deleting one directory can delete a sibling whose name merely starts with the same characters. With Appwrite'sapp-<projectId>layout, project ids are generated, so a collision of that shape is possible.Change
delete($path, true)deletes every object under the path, then the key itself, which matchesLocal, where the path may also be a file. Without$recursivethe behaviour is byte for byte what it was: oneDELETE.deletePath()already had moves into a privatedeleteByPrefix(), shared by both./, so a listing is bounded by a separator and cannot reach a sibling.delete('', true)does not recurse, so an empty path cannot turn into "list and delete the whole bucket".No public API or signature changes.
Tests
Three cases in
packages/storage/tests/Storage/Device/S3Test.php, through the existing scripted client, so the assertions are on the HTTP requests the device makes:prefix=root/dir/, sends the batch delete containing both listed keys, then deletes the key itselfDELETEdeletePath('app-1')lists withprefix=root/app-1/The first and third fail without the change: the first sends 1 request instead of 3, the third lists with
prefix=root/app-1.Verification
bin/monorepo test storage: 122 tests, 393 assertions pass. The e2e tier needs Docker, which I do not have locally, so it did not run.bin/monorepo check storage: Pint, PHPStan and Rector all pass.