diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 22 | ||||
-rw-r--r-- | lib/private/Files/Cache/Wrapper/CacheWrapper.php | 9 | ||||
-rw-r--r-- | lib/private/Files/Storage/Common.php | 2 | ||||
-rw-r--r-- | lib/private/Files/Storage/DAV.php | 2 | ||||
-rw-r--r-- | lib/private/Files/Storage/Local.php | 3 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Encoding.php | 4 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Jail.php | 4 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Quota.php | 18 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Wrapper.php | 4 | ||||
-rwxr-xr-x | lib/private/LargeFileHelper.php | 5 | ||||
-rw-r--r-- | lib/public/Files/Storage.php | 4 | ||||
-rw-r--r-- | lib/public/Files/Storage/IStorage.php | 4 |
12 files changed, 57 insertions, 24 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 9afeea7b573..afa464a8138 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -43,6 +43,7 @@ namespace OC\Files\Cache; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchQuery; +use OC\Files\Storage\Wrapper\Encryption; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\CacheEntryInsertedEvent; @@ -659,6 +660,10 @@ class Cache implements ICache { return [$this->getNumericStorageId(), $path]; } + protected function hasEncryptionWrapper(): bool { + return $this->storage->instanceOfStorage(Encryption::class); + } + /** * Move a file or folder in the cache * @@ -710,6 +715,11 @@ class Cache implements ICache { ->where($query->expr()->eq('storage', $query->createNamedParameter($sourceStorageId, IQueryBuilder::PARAM_INT))) ->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($sourcePath) . '/%'))); + // when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark + if ($sourceCache->hasEncryptionWrapper() && !$this->hasEncryptionWrapper()) { + $query->set('encrypted', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)); + } + try { $query->execute(); } catch (\OC\DatabaseException $e) { @@ -726,6 +736,12 @@ class Cache implements ICache { ->set('name', $query->createNamedParameter(basename($targetPath))) ->set('parent', $query->createNamedParameter($newParentId, IQueryBuilder::PARAM_INT)) ->whereFileId($sourceId); + + // when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark + if ($sourceCache->hasEncryptionWrapper() && !$this->hasEncryptionWrapper()) { + $query->set('encrypted', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)); + } + $query->execute(); $this->connection->commit(); @@ -1085,6 +1101,12 @@ class Cache implements ICache { throw new \RuntimeException("Invalid source cache entry on copyFromCache"); } $data = $this->cacheEntryToArray($sourceEntry); + + // when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark + if ($sourceCache instanceof Cache && $sourceCache->hasEncryptionWrapper() && !$this->hasEncryptionWrapper()) { + $data['encrypted'] = 0; + } + $fileId = $this->put($targetPath, $data); if ($fileId <= 0) { throw new \RuntimeException("Failed to copy to " . $targetPath . " from cache with source data " . json_encode($data) . " "); diff --git a/lib/private/Files/Cache/Wrapper/CacheWrapper.php b/lib/private/Files/Cache/Wrapper/CacheWrapper.php index 66ae83fd144..2cd378ad23c 100644 --- a/lib/private/Files/Cache/Wrapper/CacheWrapper.php +++ b/lib/private/Files/Cache/Wrapper/CacheWrapper.php @@ -56,6 +56,15 @@ class CacheWrapper extends Cache { return $this->cache; } + protected function hasEncryptionWrapper(): bool { + $cache = $this->getCache(); + if ($cache instanceof Cache) { + return $cache->hasEncryptionWrapper(); + } else { + return false; + } + } + /** * Make it easy for wrappers to modify every returned cache entry * diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 737c1e9d51e..3473eebc4a0 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -477,7 +477,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage { * 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; diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index fcb07cb9748..0c4a81b7491 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -486,7 +486,7 @@ class DAV extends Common { /** * @param string $path * @param mixed $data - * @return int|false + * @return int|float|false */ public function file_put_contents($path, $data) { $path = $this->cleanPath($path); diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index fe6a6d6e21a..1ff733e0d92 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -249,7 +249,7 @@ class Local extends \OC\Files\Storage\Common { $fullPath = $this->getSourcePath($path); if (PHP_INT_SIZE === 4) { $helper = new \OC\LargeFileHelper; - return $helper->getFileSize($fullPath) ?? false; + return $helper->getFileSize($fullPath); } return filesize($fullPath); } @@ -617,6 +617,7 @@ class Local extends \OC\Files\Storage\Common { } 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); diff --git a/lib/private/Files/Storage/Wrapper/Encoding.php b/lib/private/Files/Storage/Wrapper/Encoding.php index 6aba839d26d..d6006f746ad 100644 --- a/lib/private/Files/Storage/Wrapper/Encoding.php +++ b/lib/private/Files/Storage/Wrapper/Encoding.php @@ -311,7 +311,7 @@ class Encoding extends Wrapper { * * @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); @@ -396,7 +396,7 @@ class Encoding extends Wrapper { * 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)); diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 4501c96d631..e21a2cba244 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -259,7 +259,7 @@ class Jail extends Wrapper { * * @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); @@ -335,7 +335,7 @@ class Jail extends Wrapper { * 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)); diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index 5c542361c36..cfb2c455a2c 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -41,7 +41,8 @@ use OCP\Files\Storage\IStorage; 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 int|float|null $quota; protected string $sizeRoot; private SystemConfig $config; @@ -57,9 +58,9 @@ class Quota extends Wrapper { } /** - * @return int quota value + * @return int|float quota value */ - public function getQuota(): int { + public function getQuota(): int|float { if ($this->quota === null) { $quotaCallback = $this->quotaCallback; if ($quotaCallback === null) { @@ -77,7 +78,8 @@ class Quota extends Wrapper { /** * @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)) { @@ -101,7 +103,7 @@ class Quota extends Wrapper { * 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()) { @@ -128,7 +130,7 @@ class Quota extends Wrapper { * * @param string $path * @param mixed $data - * @return int|false + * @return int|float|false */ public function file_put_contents($path, $data) { if (!$this->hasQuota()) { @@ -177,7 +179,7 @@ class Quota extends Wrapper { // 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); @@ -192,7 +194,7 @@ class Quota extends Wrapper { * 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) { diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index 26b4570cc75..c2d382f5dfc 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -249,7 +249,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea * * @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); @@ -325,7 +325,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea * 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); diff --git a/lib/private/LargeFileHelper.php b/lib/private/LargeFileHelper.php index 2b2fed4e9f1..c8d6ba42eb5 100755 --- a/lib/private/LargeFileHelper.php +++ b/lib/private/LargeFileHelper.php @@ -95,10 +95,9 @@ class LargeFileHelper { * * @param string $filename Path to the file. * - * @return null|int|float Number of bytes as number (float or int) or - * null on failure. + * @return int|float Number of bytes as number (float or int) */ - public function getFileSize(string $filename): null|int|float { + public function getFileSize(string $filename): int|float { $fileSize = $this->getFileSizeViaCurl($filename); if (!is_null($fileSize)) { return $fileSize; diff --git a/lib/public/Files/Storage.php b/lib/public/Files/Storage.php index ca5276af1e8..c91d47bdcdf 100644 --- a/lib/public/Files/Storage.php +++ b/lib/public/Files/Storage.php @@ -227,7 +227,7 @@ interface Storage extends IStorage { * * @param string $path * @param mixed $data - * @return int|false + * @return int|float|false * @since 6.0.0 */ public function file_put_contents($path, $data); @@ -296,7 +296,7 @@ interface Storage extends IStorage { * 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); diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php index 1084eb7c941..7b3b9eb484e 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -224,7 +224,7 @@ interface IStorage { * * @param string $path * @param mixed $data - * @return int|false + * @return int|float|false * @since 9.0.0 */ public function file_put_contents($path, $data); @@ -293,7 +293,7 @@ interface IStorage { * 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); |