Skip to content

Commit 6f508ef

Browse files
committed
fix(AmazonS3): pass S3 error messages through to the frontend
* S3Exception to NotPermittedException in Storage/AmazonS3::writeStream() * NotPermittedException to Forbidden in Storage/Common::copyFromStorage() Improves error messages on move/copy operations when bucket quota exceeded Fixes: #58801 Signed-off-by: Jonas <jonas@freesources.org>
1 parent df6e947 commit 6f508ef

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

apps/files_external/lib/Lib/Storage/AmazonS3.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCP\Constants;
2020
use OCP\Files\FileInfo;
2121
use OCP\Files\IMimeTypeDetector;
22+
use OCP\Files\NotPermittedException;
2223
use OCP\ICache;
2324
use OCP\ICacheFactory;
2425
use OCP\ITempManager;
@@ -773,7 +774,15 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
773774
}
774775

775776
$path = $this->normalizePath($path);
776-
$this->writeObject($path, $stream, $this->mimeDetector->detectPath($path));
777+
try {
778+
$this->writeObject($path, $stream, $this->mimeDetector->detectPath($path));
779+
} catch (S3Exception $exception) {
780+
$this->logger->error($exception->getMessage(), [
781+
'app' => 'files_external',
782+
'exception' => $exception,
783+
]);
784+
throw new NotPermittedException($exception->getMessage(), $exception->getCode(), $exception);
785+
}
777786
$this->invalidateCache($path);
778787

779788
return $size;

lib/private/Files/Storage/Common.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OCP\Files\IFilenameValidator;
3333
use OCP\Files\IMimeTypeDetector;
3434
use OCP\Files\InvalidPathException;
35+
use OCP\Files\NotPermittedException;
3536
use OCP\Files\Storage\IConstructableStorage;
3637
use OCP\Files\Storage\ILockingStorage;
3738
use OCP\Files\Storage\IStorage;
@@ -562,6 +563,9 @@ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalP
562563
try {
563564
$this->writeStream($targetInternalPath, $source);
564565
$result = true;
566+
} catch (NotPermittedException $e) {
567+
Server::get(LoggerInterface::class)->warning('Failed to copy stream to storage', ['exception' => $e]);
568+
throw new ForbiddenException($e->getMessage(), false, $e);
565569
} catch (\Exception $e) {
566570
Server::get(LoggerInterface::class)->warning('Failed to copy stream to storage', ['exception' => $e]);
567571
}

0 commit comments

Comments
 (0)