From ecc76c752087b438c1befbcf2ca7d33afc26d7af Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Mar 2026 18:34:19 +0000 Subject: [PATCH] fix: address review feedback - log abort exception, fix test cleanup Agent-Logs-Url: https://github.com/appwrite/appwrite/sessions/045e63f6-9a81-447b-ba79-7391ab97fb01 Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com> --- .../Storage/Http/Buckets/Files/Delete.php | 8 ++++++-- tests/e2e/Services/Storage/StorageBase.php | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php index 596e21de26..adecc820bb 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php @@ -16,6 +16,7 @@ use Utopia\Database\Exception\NotFound as NotFoundException; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Authorization\Input; use Utopia\Database\Validator\UID; +use Utopia\Logger\Log; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\Storage\Device; @@ -66,6 +67,7 @@ class Delete extends Action ->inject('deviceForFiles') ->inject('queueForDeletes') ->inject('authorization') + ->inject('log') ->callback($this->action(...)); } @@ -77,7 +79,8 @@ class Delete extends Action Event $queueForEvents, Device $deviceForFiles, DeleteEvent $queueForDeletes, - Authorization $authorization + Authorization $authorization, + Log $log ) { $bucket = $authorization->skip(fn () => $dbForProject->getDocument('buckets', $bucketId)); @@ -113,10 +116,11 @@ class Delete extends Action $file->getAttribute('path'), ($file->getAttribute('metadata', [])['uploadId'] ?? '') ); - } catch (\Exception) { + } catch (\Exception $e) { // If the partial upload chunks are already gone from the device // (e.g. the upload never wrote anything to disk), treat it as deleted // so the pending file document can still be removed from the database. + $log->addTag('abortException', $e->getMessage()); $deviceDeleted = true; } } else { diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 453cd97605..100f5c5ca8 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -1097,9 +1097,10 @@ trait StorageBase $chunkSize = 5 * 1024 * 1024; // 5MB chunks $mimeType = mime_content_type($source); - $handle = @fopen($source, "rb"); - $chunkData = @fread($handle, $chunkSize); - @fclose($handle); + $handle = fopen($source, "rb"); + $this->assertNotFalse($handle, "Could not open test resource: $source"); + $chunkData = fread($handle, $chunkSize); + fclose($handle); $curlFile = new \CURLFile( 'data://' . $mimeType . ';base64,' . base64_encode($chunkData), @@ -1148,6 +1149,15 @@ trait StorageBase ], $this->getHeaders())); $this->assertEquals(404, $getResponse['headers']['status-code']); + + // Clean up the test bucket + $deleteBucketResponse = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(204, $deleteBucketResponse['headers']['status-code']); } public function testDeleteBucketFile(): void