Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable26] Get rid of more int casts in file size manipulations #38289

Merged
merged 2 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 7 additions & 6 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use OCP\Files\Search\ISearchQuery;
use OCP\Files\Storage\IStorage;
use OCP\IDBConnection;
use OCP\Util;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -191,8 +192,8 @@ public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader
$data['path'] = (string)$data['path'];
$data['fileid'] = (int)$data['fileid'];
$data['parent'] = (int)$data['parent'];
$data['size'] = 0 + $data['size'];
$data['unencrypted_size'] = 0 + ($data['unencrypted_size'] ?? 0);
$data['size'] = Util::numericToNumber($data['size']);
$data['unencrypted_size'] = Util::numericToNumber($data['unencrypted_size'] ?? 0);
$data['mtime'] = (int)$data['mtime'];
$data['storage_mtime'] = (int)$data['storage_mtime'];
$data['encryptedVersion'] = (int)$data['encrypted'];
Expand Down Expand Up @@ -882,7 +883,7 @@ public function getIncompleteChildrenCount($fileId) {
*
* @param string $path
* @param array $entry (optional) meta data of the folder
* @return int
* @return int|float
*/
public function calculateFolderSize($path, $entry = null) {
$totalSize = 0;
Expand All @@ -903,13 +904,13 @@ public function calculateFolderSize($path, $entry = null) {

if ($rows) {
$sizes = array_map(function (array $row) {
return (int)$row['size'];
return Util::numericToNumber($row['size']);
}, $rows);
$unencryptedOnlySizes = array_map(function (array $row) {
return (int)$row['unencrypted_size'];
return Util::numericToNumber($row['unencrypted_size']);
}, $rows);
$unencryptedSizes = array_map(function (array $row) {
return (int)(($row['unencrypted_size'] > 0) ? $row['unencrypted_size'] : $row['size']);
return Util::numericToNumber(($row['unencrypted_size'] > 0) ? $row['unencrypted_size'] : $row['size']);
}, $rows);

$sum = array_sum($sizes);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/HomeCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HomeCache extends Cache {
*
* @param string $path
* @param array $entry (optional) meta data of the folder
* @return int
* @return int|float
*/
public function calculateFolderSize($path, $entry = null) {
if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin' and $path !== 'files_versions') {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ protected function getExistingChildren($folderId) {
* @param int $folderId id for the folder to be scanned
* @param bool $lock set to false to disable getting an additional read lock during scanning
* @param array $data the data of the folder before (re)scanning the children
* @return int the size of the scanned folder or -1 if the size is unknown at this stage
* @return int|float the size of the scanned folder or -1 if the size is unknown at this stage
*/
protected function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $folderId = null, $lock = true, array $data = []) {
if ($reuse === -1) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Wrapper/CacheJail.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function correctFolderSize($path, $data = null, $isBackgroundScan = false
*
* @param string $path
* @param array $entry (optional) meta data of the folder
* @return int
* @return int|float
*/
public function calculateFolderSize($path, $entry = null) {
if ($this->getCache() instanceof Cache) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Wrapper/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function correctFolderSize($path, $data = null, $isBackgroundScan = false
*
* @param string $path
* @param array $entry (optional) meta data of the folder
* @return int
* @return int|float
*/
public function calculateFolderSize($path, $entry = null) {
if ($this->getCache() instanceof Cache) {
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Files/Storage/DAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use OCP\Files\StorageNotAvailableException;
use OCP\Http\Client\IClientService;
use OCP\ICertificateManager;
use OCP\Util;
use Psr\Http\Message\ResponseInterface;
use Sabre\DAV\Client;
use Sabre\DAV\Xml\Property\ResourceType;
Expand Down Expand Up @@ -433,7 +434,7 @@ public function free_space($path) {
return FileInfo::SPACE_UNKNOWN;
}
if (isset($response['{DAV:}quota-available-bytes'])) {
return (int)$response['{DAV:}quota-available-bytes'];
return Util::numericToNumber($response['{DAV:}quota-available-bytes']);
} else {
return FileInfo::SPACE_UNKNOWN;
}
Expand Down Expand Up @@ -587,7 +588,7 @@ public function stat($path) {
}
return [
'mtime' => isset($response['{DAV:}getlastmodified']) ? strtotime($response['{DAV:}getlastmodified']) : null,
'size' => (int)($response['{DAV:}getcontentlength'] ?? 0),
'size' => Util::numericToNumber($response['{DAV:}getcontentlength'] ?? 0),
];
} catch (\Exception $e) {
$this->convertException($e, $path);
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
use OCP\Files\IMimeTypeDetector;
use OCP\Files\Storage\IStorage;
use OCP\IConfig;
use OCP\Util;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -422,7 +423,7 @@ public function free_space($path) {
if ($space === false || is_null($space)) {
return \OCP\Files\FileInfo::SPACE_UNKNOWN;
}
return (int)$space;
return Util::numericToNumber($space);
}

public function search($query) {
Expand Down