Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make it clear that file sizes may be float on 32bits
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc authored and backportbot-nextcloud[bot] committed Apr 1, 2023
commit 3044f63743ac88794f71c7338f38c1ef28a05a2b
16 changes: 9 additions & 7 deletions lib/private/Files/Storage/Wrapper/Quota.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
class Quota extends Wrapper {
/** @var callable|null */
protected $quotaCallback;
protected ?int $quota;
/** @var int|float|null int on 64bits, float on 32bits for bigint */
protected $quota;
protected string $sizeRoot;
private SystemConfig $config;

Expand All @@ -57,7 +58,7 @@ public function __construct($parameters) {
}

/**
* @return quota value
* @return int|float quota value
*/
public function getQuota() {
if ($this->quota === null) {
Expand All @@ -77,7 +78,8 @@ private function hasQuota(): bool {

/**
* @param string $path
* @param \OC\Files\Storage\Storage $storage
* @param IStorage $storage
* @return int|float
*/
protected function getSize($path, $storage = null) {
if ($this->config->getValue('quota_include_external_storage', false)) {
Expand All @@ -101,7 +103,7 @@ protected function getSize($path, $storage = null) {
* Get free space as limited by the quota
*
* @param string $path
* @return int|bool
* @return int|float|bool
*/
public function free_space($path) {
if (!$this->hasQuota()) {
Expand All @@ -128,7 +130,7 @@ public function free_space($path) {
*
* @param string $path
* @param mixed $data
* @return int|false
* @return int|float|false
*/
public function file_put_contents($path, $data) {
if (!$this->hasQuota()) {
Expand Down Expand Up @@ -177,7 +179,7 @@ public function fopen($path, $mode) {
// don't apply quota for part files
if (!$this->isPartFile($path)) {
$free = $this->free_space($path);
if ($source && is_int($free) && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
if ($source && (is_int($free) || is_float($free)) && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
// only apply quota for files, not metadata, trash or others
if ($this->shouldApplyQuota($path)) {
return \OC\Files\Stream\Quota::wrap($source, $free);
Expand All @@ -192,7 +194,7 @@ public function fopen($path, $mode) {
* Checks whether the given path is a part file
*
* @param string $path Path that may identify a .part file
* @return string File path without .part extension
* @return bool
* @note this is needed for reusing keys
*/
private function isPartFile($path) {
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Storage/Wrapper/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function file_get_contents($path) {
*
* @param string $path
* @param mixed $data
* @return int|false
* @return int|float|false
*/
public function file_put_contents($path, $data) {
return $this->getWrapperStorage()->file_put_contents($path, $data);
Expand Down Expand Up @@ -325,7 +325,7 @@ public function hash($type, $path, $raw = false) {
* see https://www.php.net/manual/en/function.free_space.php
*
* @param string $path
* @return int|bool
* @return int|float|bool
*/
public function free_space($path) {
return $this->getWrapperStorage()->free_space($path);
Expand Down
4 changes: 2 additions & 2 deletions lib/public/Files/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function file_get_contents($path);
*
* @param string $path
* @param mixed $data
* @return int|false
* @return int|float|false
* @since 6.0.0
*/
public function file_put_contents($path, $data);
Expand Down Expand Up @@ -296,7 +296,7 @@ public function hash($type, $path, $raw = false);
* see https://www.php.net/manual/en/function.disk-free-space.php
*
* @param string $path
* @return int|bool
* @return int|float|bool
* @since 6.0.0
*/
public function free_space($path);
Expand Down
4 changes: 2 additions & 2 deletions lib/public/Files/Storage/IStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function file_get_contents($path);
*
* @param string $path
* @param mixed $data
* @return int|false
* @return int|float|false
* @since 9.0.0
*/
public function file_put_contents($path, $data);
Expand Down Expand Up @@ -293,7 +293,7 @@ public function hash($type, $path, $raw = false);
* see https://www.php.net/manual/en/function.free_space.php
*
* @param string $path
* @return int|bool
* @return int|float|bool
* @since 9.0.0
*/
public function free_space($path);
Expand Down