Skip to content

Commit

Permalink
don't alter file when there is not enough free space
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <[email protected]>
  • Loading branch information
grnd-alt committed Apr 4, 2024
1 parent b6dff30 commit 1fe1a26
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/Controller/WopiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,21 @@ public function putFile($fileId,

$content = fopen('php://input', 'rb');

// Get expected FileSize after writing
$storage = \OC_Helper::getStorageInfo($path);

Check failure on line 489 in lib/Controller/WopiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedMethod

lib/Controller/WopiController.php:489:15: UndefinedMethod: Method OC_Helper::getstorageinfo does not exist (see https://psalm.dev/022)
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);
Expand Down

0 comments on commit 1fe1a26

Please sign in to comment.