diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 54cd4d5ba2b..106dc722c7f 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -91,11 +91,15 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, } public function filesize(string $path): int|float|false { - if ($this->is_dir($path)) { - return 0; //by definition + $type = $this->filetype($path); + if ($type === false) { + return false; + } + if ($type !== 'file') { + return 0; } else { $stat = $this->stat($path); - return isset($stat['size']) ? $stat['size'] : 0; + return $stat['size'] ?? 0; } } diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index c46d4c6c8eb..6e506a3f518 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -215,7 +215,7 @@ class Local extends \OC\Files\Storage\Common { } public function filetype(string $path): string|false { - $filetype = filetype($this->getSourcePath($path)); + $filetype = @filetype($this->getSourcePath($path)); if ($filetype == 'link') { $filetype = filetype(realpath($this->getSourcePath($path))); } @@ -223,7 +223,11 @@ class Local extends \OC\Files\Storage\Common { } public function filesize(string $path): int|float|false { - if (!$this->is_file($path)) { + $type = $this->filetype($path); + if ($type === false) { + return false; + } + if ($type !== 'file') { return 0; } $fullPath = $this->getSourcePath($path);