Repository navigation
Conversation
…ilures 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, and a per-key failure reported inside a 200 bulk delete response is raised instead of being read as success.
🟢 Tier S · Ready to merge
This pull request makes recursive S3 deletion remove objects beneath a path, limits directory deletion to its own prefix, and reports per-key bulk-delete failures. The latest commits escape object keys in bulk-delete XML, handle XML failures returned as undecoded strings, and replace request-focused deletion tests with in-memory bucket checks. Latest changes: The newest commits escape listed keys in bulk-delete requests, decode nonempty raw XML responses before checking for errors, and add outcome-based deletion tests plus a raw-response failure test.
Note @Neekoras does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve. 📂 Walkthrough · 2
✅ Fixed since the last review · 1
Reviewed the commits since |
|
… response A key holding & or < made the request malformed, and a failure that arrived undecoded read as success. The delete tests now assert which objects survive against an in-memory bucket rather than the shape of each request.
|
Closing this: Worth noting #13808 is still open even though the code looks fixed, in case someone wants to close it or there is a remaining case I am not seeing. If any part of what I had is still uncovered, I am happy to reopen with just that piece. |
What does this PR do?
Re-opened here at @ChiragAgg5k's request on utopia-php/monorepo#352: "Storage now lives in
packages/storagein appwrite/appwrite (#13926), and this copy is being retired. @Neekoras, please re-open this againstpackages/storagethere if you still want it." Same change, on this copy, plus the one review finding that PR received.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.The deletes worker removes a project's files that 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. This is the library half of #13808. The main symptom reported there, bucket deletion leaving files, comes fromgetDevice()folding the S3 bucket name into the device root, which makeslistObjects()address the service endpoint instead of the bucket. That one is not fixed here: the root is part of thepathstored on every existing file document, so changing it needs a migration, which is a maintainer's call.Two more problems in the same code:
deletePath()lists with"{root}/{path}"as the prefix, with no trailing separator, sodeletePath('app-1')also matchesapp-12/.... One directory's deletion can take a sibling whose name merely starts with the same characters, and project ids are generated, so that shape is reachable.200. The result was never inspected, so a delete that S3 refused, for example withAccessDenied, was read as success.Changes
delete($path, true)deletes every object under the path, then the key itself, matchingLocal, where the path may also be a file. Without$recursivethe behaviour is unchanged: oneDELETE.deletePath()already had moves into a privatedeleteByPrefix(), shared by both./, so a listing cannot reach a sibling.<Error>entries raisesRemoteExceptionnaming the key, code and message. The request sets<Quiet>true</Quiet>, so a healthy response carries no entries at all.delete('', true)does not recurse, so an empty path cannot become "list and delete the whole bucket".No public API or signature changes.
Test Plan
Four cases in
packages/storage/tests/Device/S3Test.php, through the existing scripted client, so the assertions are on the requests the device actually makes:prefix=root/dir/, sends the batch delete containing both listed keys, then deletes the key itselfDELETEdeletePath('app-1')lists withprefix=root/app-1/200with anAccessDeniedentry raises instead of returning successThree of the four fail on
main: the first sends 1 request instead of 3, the third lists withprefix=root/app-1, and the fourth throws nothing.The e2e tier needs Docker, which I do not have on this machine, so it did not run here.
Related PRs and Issues
Checklist