Skip to content

Commit bac2dfa

Browse files
mejo-backportbot[bot]
authored andcommitted
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 e6994d1 commit bac2dfa

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;
@@ -761,7 +762,15 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
761762
}
762763

763764
$path = $this->normalizePath($path);
764-
$this->writeObject($path, $stream, $this->mimeDetector->detectPath($path));
765+
try {
766+
$this->writeObject($path, $stream, $this->mimeDetector->detectPath($path));
767+
} catch (S3Exception $exception) {
768+
$this->logger->error($exception->getMessage(), [
769+
'app' => 'files_external',
770+
'exception' => $exception,
771+
]);
772+
throw new NotPermittedException($exception->getMessage(), $exception->getCode(), $exception);
773+
}
765774
$this->invalidateCache($path);
766775

767776
return $size;

lib/private/Files/Storage/Common.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCP\Files\GenericFileException;
3030
use OCP\Files\IFilenameValidator;
3131
use OCP\Files\InvalidPathException;
32+
use OCP\Files\NotPermittedException;
3233
use OCP\Files\Storage\IConstructableStorage;
3334
use OCP\Files\Storage\ILockingStorage;
3435
use OCP\Files\Storage\IStorage;
@@ -519,6 +520,9 @@ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalP
519520
try {
520521
$this->writeStream($targetInternalPath, $source);
521522
$result = true;
523+
} catch (NotPermittedException $e) {
524+
Server::get(LoggerInterface::class)->warning('Failed to copy stream to storage', ['exception' => $e]);
525+
throw new ForbiddenException($e->getMessage(), false, $e);
522526
} catch (\Exception $e) {
523527
Server::get(LoggerInterface::class)->warning('Failed to copy stream to storage', ['exception' => $e]);
524528
}

0 commit comments

Comments
 (0)