Skip to content

Commit cebcc6c

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 ba01951 commit cebcc6c

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
@@ -20,6 +20,7 @@
2020
use OCP\Constants;
2121
use OCP\Files\FileInfo;
2222
use OCP\Files\IMimeTypeDetector;
23+
use OCP\Files\NotPermittedException;
2324
use OCP\ICache;
2425
use OCP\ICacheFactory;
2526
use OCP\ITempManager;
@@ -772,7 +773,15 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
772773
}
773774

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

778787
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)