File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed
lib/private/Files/Storage Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -92,11 +92,15 @@ public function is_file(string $path): bool {
9292 }
9393
9494 public function filesize (string $ path ): int |float |false {
95- if ($ this ->is_dir ($ path )) {
96- return 0 ; //by definition
95+ $ type = $ this ->filetype ($ path );
96+ if ($ type === false ) {
97+ return false ;
98+ }
99+ if ($ type !== 'file ' ) {
100+ return 0 ;
97101 } else {
98102 $ stat = $ this ->stat ($ path );
99- return isset ( $ stat ['size ' ]) ? $ stat [ ' size ' ] : 0 ;
103+ return $ stat ['size ' ] ?? 0 ;
100104 }
101105 }
102106
Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff line change @@ -311,6 +311,8 @@ public function testStat(): void {
311311
312312 $ this ->instance ->unlink ('/lorem.txt ' );
313313 $ this ->assertTrue ($ this ->instance ->hasUpdated ('/ ' , $ mtimeStart - 5 ));
314+
315+ $ this ->assertFalse ($ this ->instance ->filesize ('/non-existing-file.txt ' ));
314316 }
315317
316318 /**
You can’t perform that action at this time.
0 commit comments