fix: correctly return false for filesize on non-existing file

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2026-02-24 15:32:20 +01:00
parent 87504e27d0
commit 32299a8113
No known key found for this signature in database
GPG key ID: 42B69D8A64526EFB
2 changed files with 13 additions and 5 deletions

View file

@ -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;
}
}

View file

@ -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);