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

[stable24] Quota value as float for 32-bit systems #35940

Merged
merged 5 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 1 addition & 2 deletions lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public function test() {
* get the free space in the storage
*
* @param string $path
* @return int|false
* @return int|float|false
*/
public function free_space($path) {
return \OCP\Files\FileInfo::SPACE_UNKNOWN;
Expand Down Expand Up @@ -518,7 +518,6 @@ public function getDirectDownload($path) {
* @throws InvalidPathException
*/
public function verifyPath($path, $fileName) {

// verify empty and dot files
$trimmed = trim($fileName);
if ($trimmed === '') {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/DAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public function touch($path, $mtime = null) {
/**
* @param string $path
* @param mixed $data
* @return int|false
* @return int|float|false
*/
public function file_put_contents($path, $data) {
$path = $this->cleanPath($path);
Expand Down
1 change: 1 addition & 0 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
}

public function writeStream(string $path, $stream, int $size = null): int {
/** @var int|false $result We consider here that returned size will never be a float because we write less than 4GB */
$result = $this->file_put_contents($path, $stream);
if (is_resource($stream)) {
fclose($stream);
Expand Down
7 changes: 3 additions & 4 deletions lib/private/Files/Storage/Wrapper/Encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
* the actual given name and then try its NFD form.
*/
class Encoding extends Wrapper {

/**
* @var ICache
*/
Expand Down Expand Up @@ -213,7 +212,7 @@ public function filetype($path) {
* The result for filesize when called on a folder is required to be 0
*
* @param string $path
* @return int|bool
* @return int|float|bool
*/
public function filesize($path) {
return $this->storage->filesize($this->findPathToUse($path));
Expand Down Expand Up @@ -315,7 +314,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->storage->file_put_contents($this->findPathToUse($path), $data);
Expand Down Expand Up @@ -400,7 +399,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->storage->free_space($this->findPathToUse($path));
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Files/Storage/Wrapper/Jail.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function filetype($path) {
* The result for filesize when called on a folder is required to be 0
*
* @param string $path
* @return int|bool
* @return int|float|bool
*/
public function filesize($path) {
return $this->getWrapperStorage()->filesize($this->getUnjailedPath($path));
Expand Down Expand Up @@ -262,7 +262,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($this->getUnjailedPath($path), $data);
Expand Down Expand Up @@ -338,7 +338,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($this->getUnjailedPath($path));
Expand Down
18 changes: 8 additions & 10 deletions lib/private/Files/Storage/Wrapper/Quota.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
use OCP\Files\Storage\IStorage;

class Quota extends Wrapper {

/**
* @var int $quota
*/
/** @var int|float|null int on 64bits, float on 32bits for bigint */
protected $quota;

/**
Expand All @@ -61,15 +58,16 @@ public function __construct($parameters) {
}

/**
* @return int quota value
* @return int|float quota value
Fixed Show fixed Hide fixed
*/
public function getQuota() {
return $this->quota;
}

/**
* @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 Down Expand Up @@ -97,7 +95,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->quota < 0 || strpos($path, 'cache') === 0 || strpos($path, 'uploads') === 0) {
Expand Down Expand Up @@ -125,7 +123,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) {
$free = $this->free_space($path);
Expand Down Expand Up @@ -165,7 +163,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 @@ -179,7 +177,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
6 changes: 3 additions & 3 deletions lib/private/Files/Storage/Wrapper/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function filetype($path) {
* The result for filesize when called on a folder is required to be 0
*
* @param string $path
* @return int|bool
* @return int|float|bool
*/
public function filesize($path) {
return $this->getWrapperStorage()->filesize($path);
Expand Down Expand Up @@ -252,7 +252,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 @@ -328,7 +328,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
2 changes: 1 addition & 1 deletion lib/private/LargeFileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function formatUnsignedInteger($number) {
*
* @param string $filename Path to the file.
*
* @return null|int|float Number of bytes as number (float or int) or
* @return int|float Number of bytes as number (float or int) or
* null on failure.
*/
public function getFileSize($filename) {
Expand Down
6 changes: 3 additions & 3 deletions lib/public/Files/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function filetype($path);
* The result for filesize when called on a folder is required to be 0
*
* @param string $path
* @return int|bool
* @return int|float|bool
* @since 6.0.0
*/
public function filesize($path);
Expand Down 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.free_space.php
*
* @param string $path
* @return int|bool
* @return int|float|bool
* @since 6.0.0
*/
public function free_space($path);
Expand Down
6 changes: 3 additions & 3 deletions lib/public/Files/Storage/IStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function filetype($path);
* The result for filesize when called on a folder is required to be 0
*
* @param string $path
* @return int|bool
* @return int|float|bool
* @since 9.0.0
*/
public function filesize($path);
Expand Down 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