Skip to content

Commit 32299a8

Browse files
committed
fix: correctly return false for filesize on non-existing file
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 87504e2 commit 32299a8

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

lib/private/Files/Storage/Common.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ public function is_file(string $path): bool {
9191
}
9292

9393
public function filesize(string $path): int|float|false {
94-
if ($this->is_dir($path)) {
95-
return 0; //by definition
94+
$type = $this->filetype($path);
95+
if ($type === false) {
96+
return false;
97+
}
98+
if ($type !== 'file') {
99+
return 0;
96100
} else {
97101
$stat = $this->stat($path);
98-
return isset($stat['size']) ? $stat['size'] : 0;
102+
return $stat['size'] ?? 0;
99103
}
100104
}
101105

lib/private/Files/Storage/Local.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,19 @@ public function getMetaData(string $path): ?array {
215215
}
216216

217217
public function filetype(string $path): string|false {
218-
$filetype = filetype($this->getSourcePath($path));
218+
$filetype = @filetype($this->getSourcePath($path));
219219
if ($filetype == 'link') {
220220
$filetype = filetype(realpath($this->getSourcePath($path)));
221221
}
222222
return $filetype;
223223
}
224224

225225
public function filesize(string $path): int|float|false {
226-
if (!$this->is_file($path)) {
226+
$type = $this->filetype($path);
227+
if ($type === false) {
228+
return false;
229+
}
230+
if ($type !== 'file') {
227231
return 0;
228232
}
229233
$fullPath = $this->getSourcePath($path);

0 commit comments

Comments
 (0)