diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index d58042b042c39..696232da64fa0 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -97,11 +97,15 @@ public function is_file(string $path): bool { } 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 a27489ce7b6ba..e3afc6bd01702 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -218,7 +218,7 @@ public function getMetaData(string $path): ?array { } 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))); } @@ -226,7 +226,11 @@ public function filetype(string $path): string|false { } 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); diff --git a/tests/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php index 60e696739eed5..9107d99cd6738 100644 --- a/tests/lib/Files/Storage/Storage.php +++ b/tests/lib/Files/Storage/Storage.php @@ -311,6 +311,8 @@ public function testStat(): void { $this->instance->unlink('/lorem.txt'); $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); + + $this->assertFalse($this->instance->filesize('/non-existing-file.txt')); } /**