From 1fe1a268b56f19d19b88120b9f89c54b849dc9ce Mon Sep 17 00:00:00 2001 From: grnd-alt Date: Thu, 4 Apr 2024 15:23:33 +0200 Subject: [PATCH] don't alter file when there is not enough free space Signed-off-by: grnd-alt --- lib/Controller/WopiController.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index 27d85dbcad..593c939122 100644 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -485,10 +485,21 @@ public function putFile($fileId, $content = fopen('php://input', 'rb'); + // Get expected FileSize after writing + $storage = \OC_Helper::getStorageInfo($path); + fseek($content,0,SEEK_END); + $finalSize = ftell($content) + $file->getSize(); + rewind( $content ); + try { - $this->wrappedFilesystemOperation($wopi, function () use ($file, $content) { - return $file->putContent($content); - }); + if ($finalSize <= $storage['free']){ + $this->wrappedFilesystemOperation($wopi, function () use ($file, $content) { + return $file->putContent($content); + }); + } + else { + throw new \Exception('Not enough storage'); + } } catch (LockedException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); return new JSONResponse(['message' => 'File locked'], Http::STATUS_INTERNAL_SERVER_ERROR);