Skip to content

Commit

Permalink
get freespace from file parent
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 e148e9b commit cd6535b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
14 changes: 7 additions & 7 deletions lib/Controller/WopiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,20 +485,20 @@ public function putFile($fileId,

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

$freespace = $file->getParent()->getFreeSpace();

// Get expected FileSize after writing
$storage = \OC_Helper::getStorageInfo($path);
fseek($content, 0, SEEK_END);
$finalSize = ftell($content) + $file->getSize();
$finalSize = ftell($content);
rewind($content);

try {
if ($finalSize <= $storage['free']) {
$this->wrappedFilesystemOperation($wopi, function () use ($file, $content) {
return $file->putContent($content);
});
} else {
if ($finalSize > $freespace) {
throw new \Exception('Not enough storage');
}
$this->wrappedFilesystemOperation($wopi, function () use ($file, $content) {
return $file->putContent($content);
});
} catch (LockedException $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
return new JSONResponse(['message' => 'File locked'], Http::STATUS_INTERNAL_SERVER_ERROR);
Expand Down
5 changes: 0 additions & 5 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
</ignoreFiles>
</extraFiles>
<issueHandlers>
<UndefinedMethod>
<errorLevel type="suppress">
<referencedMethod name="OC_Helper::getstorageinfo" />
</errorLevel>
</UndefinedMethod>
<UndefinedMagicMethod>
<errorLevel type="suppress">
<referencedMethod name="/Db\\.*::.*/" />
Expand Down

0 comments on commit cd6535b

Please sign in to comment.