Skip to content

Commit 3f19e13

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

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
@@ -97,11 +97,15 @@ public function is_file(string $path): bool {
9797
}
9898

9999
public function filesize(string $path): int|float|false {
100-
if ($this->is_dir($path)) {
101-
return 0; //by definition
100+
$type = $this->filetype($path);
101+
if ($type === false) {
102+
return false;
103+
}
104+
if ($type !== 'file') {
105+
return 0;
102106
} else {
103107
$stat = $this->stat($path);
104-
return isset($stat['size']) ? $stat['size'] : 0;
108+
return $stat['size'] ?? 0;
105109
}
106110
}
107111

lib/private/Files/Storage/Local.php

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

220220
public function filetype(string $path): string|false {
221-
$filetype = filetype($this->getSourcePath($path));
221+
$filetype = @filetype($this->getSourcePath($path));
222222
if ($filetype === 'link') {
223223
$filetype = filetype(realpath($this->getSourcePath($path)));
224224
}
225225
return $filetype;
226226
}
227227

228228
public function filesize(string $path): int|float|false {
229-
if (!$this->is_file($path)) {
229+
$type = $this->filetype($path);
230+
if ($type === false) {
231+
return false;
232+
}
233+
if ($type !== 'file') {
230234
return 0;
231235
}
232236
$fullPath = $this->getSourcePath($path);

0 commit comments

Comments
 (0)