Skip to content

Commit 8362eea

Browse files
authored
Merge pull request #38196 from nextcloud/fix/fix-32bits-freespace-and-sizes
Get rid of more int casts in file size manipulations
2 parents b9026ac + ae525e1 commit 8362eea

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

lib/private/Files/Cache/Cache.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
use OCP\Files\Search\ISearchQuery;
6161
use OCP\Files\Storage\IStorage;
6262
use OCP\IDBConnection;
63+
use OCP\Util;
6364
use Psr\Log\LoggerInterface;
6465

6566
/**
@@ -191,8 +192,8 @@ public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader
191192
$data['path'] = (string)$data['path'];
192193
$data['fileid'] = (int)$data['fileid'];
193194
$data['parent'] = (int)$data['parent'];
194-
$data['size'] = 0 + $data['size'];
195-
$data['unencrypted_size'] = 0 + ($data['unencrypted_size'] ?? 0);
195+
$data['size'] = Util::numericToNumber($data['size']);
196+
$data['unencrypted_size'] = Util::numericToNumber($data['unencrypted_size'] ?? 0);
196197
$data['mtime'] = (int)$data['mtime'];
197198
$data['storage_mtime'] = (int)$data['storage_mtime'];
198199
$data['encryptedVersion'] = (int)$data['encrypted'];
@@ -900,7 +901,7 @@ public function getIncompleteChildrenCount($fileId) {
900901
*
901902
* @param string $path
902903
* @param array|null|ICacheEntry $entry (optional) meta data of the folder
903-
* @return int
904+
* @return int|float
904905
*/
905906
public function calculateFolderSize($path, $entry = null) {
906907
return $this->calculateFolderSizeInner($path, $entry);
@@ -913,7 +914,7 @@ public function calculateFolderSize($path, $entry = null) {
913914
* @param string $path
914915
* @param array|null|ICacheEntry $entry (optional) meta data of the folder
915916
* @param bool $ignoreUnknown don't mark the folder size as unknown if any of it's children are unknown
916-
* @return int
917+
* @return int|float
917918
*/
918919
protected function calculateFolderSizeInner(string $path, $entry = null, bool $ignoreUnknown = false) {
919920
$totalSize = 0;
@@ -937,13 +938,13 @@ protected function calculateFolderSizeInner(string $path, $entry = null, bool $i
937938

938939
if ($rows) {
939940
$sizes = array_map(function (array $row) {
940-
return (int)$row['size'];
941+
return Util::numericToNumber($row['size']);
941942
}, $rows);
942943
$unencryptedOnlySizes = array_map(function (array $row) {
943-
return (int)$row['unencrypted_size'];
944+
return Util::numericToNumber($row['unencrypted_size']);
944945
}, $rows);
945946
$unencryptedSizes = array_map(function (array $row) {
946-
return (int)(($row['unencrypted_size'] > 0) ? $row['unencrypted_size'] : $row['size']);
947+
return Util::numericToNumber(($row['unencrypted_size'] > 0) ? $row['unencrypted_size'] : $row['size']);
947948
}, $rows);
948949

949950
$sum = array_sum($sizes);

lib/private/Files/Cache/HomeCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class HomeCache extends Cache {
3636
*
3737
* @param string $path
3838
* @param array|null|ICacheEntry $entry (optional) meta data of the folder
39-
* @return int
39+
* @return int|float
4040
*/
4141
public function calculateFolderSize($path, $entry = null) {
4242
if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin' and $path !== 'files_versions') {

lib/private/Files/Cache/Scanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ protected function getExistingChildren($folderId) {
386386
* @param int $folderId id for the folder to be scanned
387387
* @param bool $lock set to false to disable getting an additional read lock during scanning
388388
* @param array $data the data of the folder before (re)scanning the children
389-
* @return int the size of the scanned folder or -1 if the size is unknown at this stage
389+
* @return int|float the size of the scanned folder or -1 if the size is unknown at this stage
390390
*/
391391
protected function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $folderId = null, $lock = true, array $data = []) {
392392
if ($reuse === -1) {

lib/private/Files/Cache/Wrapper/CacheJail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public function correctFolderSize($path, $data = null, $isBackgroundScan = false
240240
*
241241
* @param string $path
242242
* @param array|null|ICacheEntry $entry (optional) meta data of the folder
243-
* @return int
243+
* @return int|float
244244
*/
245245
public function calculateFolderSize($path, $entry = null) {
246246
if ($this->getCache() instanceof Cache) {

lib/private/Files/Cache/Wrapper/CacheWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public function correctFolderSize($path, $data = null, $isBackgroundScan = false
250250
*
251251
* @param string $path
252252
* @param array|null|ICacheEntry $entry (optional) meta data of the folder
253-
* @return int
253+
* @return int|float
254254
*/
255255
public function calculateFolderSize($path, $entry = null) {
256256
if ($this->getCache() instanceof Cache) {

lib/private/Files/Storage/DAV.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
use OCP\Files\StorageNotAvailableException;
5252
use OCP\Http\Client\IClientService;
5353
use OCP\ICertificateManager;
54+
use OCP\Util;
5455
use Psr\Http\Message\ResponseInterface;
5556
use Sabre\DAV\Client;
5657
use Sabre\DAV\Xml\Property\ResourceType;
@@ -451,7 +452,7 @@ public function free_space($path) {
451452
return FileInfo::SPACE_UNKNOWN;
452453
}
453454
if (isset($response['{DAV:}quota-available-bytes'])) {
454-
return (int)$response['{DAV:}quota-available-bytes'];
455+
return Util::numericToNumber($response['{DAV:}quota-available-bytes']);
455456
} else {
456457
return FileInfo::SPACE_UNKNOWN;
457458
}
@@ -605,7 +606,7 @@ public function stat($path) {
605606
}
606607
return [
607608
'mtime' => isset($response['{DAV:}getlastmodified']) ? strtotime($response['{DAV:}getlastmodified']) : null,
608-
'size' => (int)($response['{DAV:}getcontentlength'] ?? 0),
609+
'size' => Util::numericToNumber($response['{DAV:}getcontentlength'] ?? 0),
609610
];
610611
} catch (\Exception $e) {
611612
$this->convertException($e, $path);

lib/private/Files/Storage/Local.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use OCP\Files\IMimeTypeDetector;
5353
use OCP\Files\Storage\IStorage;
5454
use OCP\IConfig;
55+
use OCP\Util;
5556
use Psr\Log\LoggerInterface;
5657

5758
/**
@@ -422,7 +423,7 @@ public function free_space($path) {
422423
if ($space === false || is_null($space)) {
423424
return \OCP\Files\FileInfo::SPACE_UNKNOWN;
424425
}
425-
return (int)$space;
426+
return Util::numericToNumber($space);
426427
}
427428

428429
public function search($query) {

0 commit comments

Comments
 (0)