mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
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>
This commit is contained in:
co-authored by
Meldiron
parent
898e8e214b
commit
ecc76c7520
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user