Skip to content

Commit 06ab4f2

Browse files
authored
Merge pull request #37344 from nextcloud/backport/35734/master
[master] [stable25] Quota value as float for 32-bit systems
2 parents 701cc1e + 8104d9f commit 06ab4f2

File tree

10 files changed

+26
-24
lines changed

10 files changed

+26
-24
lines changed

lib/private/Files/Storage/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ public function test() {
477477
* get the free space in the storage
478478
*
479479
* @param string $path
480-
* @return int|false
480+
* @return int|float|false
481481
*/
482482
public function free_space($path) {
483483
return \OCP\Files\FileInfo::SPACE_UNKNOWN;

lib/private/Files/Storage/DAV.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public function touch($path, $mtime = null) {
486486
/**
487487
* @param string $path
488488
* @param mixed $data
489-
* @return int|false
489+
* @return int|float|false
490490
*/
491491
public function file_put_contents($path, $data) {
492492
$path = $this->cleanPath($path);

lib/private/Files/Storage/Local.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public function filesize($path): false|int|float {
249249
$fullPath = $this->getSourcePath($path);
250250
if (PHP_INT_SIZE === 4) {
251251
$helper = new \OC\LargeFileHelper;
252-
return $helper->getFileSize($fullPath) ?? false;
252+
return $helper->getFileSize($fullPath);
253253
}
254254
return filesize($fullPath);
255255
}
@@ -617,6 +617,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
617617
}
618618

619619
public function writeStream(string $path, $stream, int $size = null): int {
620+
/** @var int|false $result We consider here that returned size will never be a float because we write less than 4GB */
620621
$result = $this->file_put_contents($path, $stream);
621622
if (is_resource($stream)) {
622623
fclose($stream);

lib/private/Files/Storage/Wrapper/Encoding.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public function file_get_contents($path) {
311311
*
312312
* @param string $path
313313
* @param mixed $data
314-
* @return int|false
314+
* @return int|float|false
315315
*/
316316
public function file_put_contents($path, $data) {
317317
return $this->storage->file_put_contents($this->findPathToUse($path), $data);
@@ -396,7 +396,7 @@ public function hash($type, $path, $raw = false) {
396396
* see https://www.php.net/manual/en/function.free_space.php
397397
*
398398
* @param string $path
399-
* @return int|bool
399+
* @return int|float|bool
400400
*/
401401
public function free_space($path) {
402402
return $this->storage->free_space($this->findPathToUse($path));

lib/private/Files/Storage/Wrapper/Jail.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function file_get_contents($path) {
259259
*
260260
* @param string $path
261261
* @param mixed $data
262-
* @return int|false
262+
* @return int|float|false
263263
*/
264264
public function file_put_contents($path, $data) {
265265
return $this->getWrapperStorage()->file_put_contents($this->getUnjailedPath($path), $data);
@@ -335,7 +335,7 @@ public function hash($type, $path, $raw = false) {
335335
* see https://www.php.net/manual/en/function.free_space.php
336336
*
337337
* @param string $path
338-
* @return int|bool
338+
* @return int|float|bool
339339
*/
340340
public function free_space($path) {
341341
return $this->getWrapperStorage()->free_space($this->getUnjailedPath($path));

lib/private/Files/Storage/Wrapper/Quota.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
class Quota extends Wrapper {
4242
/** @var callable|null */
4343
protected $quotaCallback;
44-
protected ?int $quota;
44+
/** @var int|float|null int on 64bits, float on 32bits for bigint */
45+
protected int|float|null $quota;
4546
protected string $sizeRoot;
4647
private SystemConfig $config;
4748

@@ -57,9 +58,9 @@ public function __construct($parameters) {
5758
}
5859

5960
/**
60-
* @return int quota value
61+
* @return int|float quota value
6162
*/
62-
public function getQuota(): int {
63+
public function getQuota(): int|float {
6364
if ($this->quota === null) {
6465
$quotaCallback = $this->quotaCallback;
6566
if ($quotaCallback === null) {
@@ -77,7 +78,8 @@ private function hasQuota(): bool {
7778

7879
/**
7980
* @param string $path
80-
* @param \OC\Files\Storage\Storage $storage
81+
* @param IStorage $storage
82+
* @return int|float
8183
*/
8284
protected function getSize($path, $storage = null) {
8385
if ($this->config->getValue('quota_include_external_storage', false)) {
@@ -101,7 +103,7 @@ protected function getSize($path, $storage = null) {
101103
* Get free space as limited by the quota
102104
*
103105
* @param string $path
104-
* @return int|bool
106+
* @return int|float|bool
105107
*/
106108
public function free_space($path) {
107109
if (!$this->hasQuota()) {
@@ -128,7 +130,7 @@ public function free_space($path) {
128130
*
129131
* @param string $path
130132
* @param mixed $data
131-
* @return int|false
133+
* @return int|float|false
132134
*/
133135
public function file_put_contents($path, $data) {
134136
if (!$this->hasQuota()) {
@@ -177,7 +179,7 @@ public function fopen($path, $mode) {
177179
// don't apply quota for part files
178180
if (!$this->isPartFile($path)) {
179181
$free = $this->free_space($path);
180-
if ($source && is_int($free) && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
182+
if ($source && (is_int($free) || is_float($free)) && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
181183
// only apply quota for files, not metadata, trash or others
182184
if ($this->shouldApplyQuota($path)) {
183185
return \OC\Files\Stream\Quota::wrap($source, $free);
@@ -192,7 +194,7 @@ public function fopen($path, $mode) {
192194
* Checks whether the given path is a part file
193195
*
194196
* @param string $path Path that may identify a .part file
195-
* @return string File path without .part extension
197+
* @return bool
196198
* @note this is needed for reusing keys
197199
*/
198200
private function isPartFile($path) {

lib/private/Files/Storage/Wrapper/Wrapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public function file_get_contents($path) {
249249
*
250250
* @param string $path
251251
* @param mixed $data
252-
* @return int|false
252+
* @return int|float|false
253253
*/
254254
public function file_put_contents($path, $data) {
255255
return $this->getWrapperStorage()->file_put_contents($path, $data);
@@ -325,7 +325,7 @@ public function hash($type, $path, $raw = false) {
325325
* see https://www.php.net/manual/en/function.free_space.php
326326
*
327327
* @param string $path
328-
* @return int|bool
328+
* @return int|float|bool
329329
*/
330330
public function free_space($path) {
331331
return $this->getWrapperStorage()->free_space($path);

lib/private/LargeFileHelper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ public function formatUnsignedInteger(int|float|string $number): string {
9595
*
9696
* @param string $filename Path to the file.
9797
*
98-
* @return null|int|float Number of bytes as number (float or int) or
99-
* null on failure.
98+
* @return int|float Number of bytes as number (float or int)
10099
*/
101-
public function getFileSize(string $filename): null|int|float {
100+
public function getFileSize(string $filename): int|float {
102101
$fileSize = $this->getFileSizeViaCurl($filename);
103102
if (!is_null($fileSize)) {
104103
return $fileSize;

lib/public/Files/Storage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function file_get_contents($path);
227227
*
228228
* @param string $path
229229
* @param mixed $data
230-
* @return int|false
230+
* @return int|float|false
231231
* @since 6.0.0
232232
*/
233233
public function file_put_contents($path, $data);
@@ -296,7 +296,7 @@ public function hash($type, $path, $raw = false);
296296
* see https://www.php.net/manual/en/function.disk-free-space.php
297297
*
298298
* @param string $path
299-
* @return int|bool
299+
* @return int|float|bool
300300
* @since 6.0.0
301301
*/
302302
public function free_space($path);

lib/public/Files/Storage/IStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function file_get_contents($path);
224224
*
225225
* @param string $path
226226
* @param mixed $data
227-
* @return int|false
227+
* @return int|float|false
228228
* @since 9.0.0
229229
*/
230230
public function file_put_contents($path, $data);
@@ -293,7 +293,7 @@ public function hash($type, $path, $raw = false);
293293
* see https://www.php.net/manual/en/function.free_space.php
294294
*
295295
* @param string $path
296-
* @return int|bool
296+
* @return int|float|bool
297297
* @since 9.0.0
298298
*/
299299
public function free_space($path);

0 commit comments

Comments
 (0)