@@ -478,7 +478,7 @@ public function delete($path): void
478478 */
479479 public function directoryExists (string $ path ): bool
480480 {
481- return $ this ->fileExists ( $ path );
481+ return $ this ->exists (StorageAttributes:: TYPE_DIRECTORY , $ path );
482482 }
483483
484484 /**
@@ -487,16 +487,7 @@ public function directoryExists(string $path): bool
487487 */
488488 public function fileExists (string $ path ): bool
489489 {
490- $ list = new DirectoryListing ($ this ->listContents (
491- Util::splitPathIntoDirectoryAndFile ($ path )['dir ' ],
492- false
493- ));
494-
495- $ count = $ list ->filter (function (StorageAttributes $ item ) use ($ path ) {
496- return Util::normalizePath ($ item ->path ()) === Util::normalizePath ($ path );
497- })->toArray ();
498-
499- return (bool ) count ($ count );
490+ return $ this ->exists (StorageAttributes::TYPE_FILE , $ path );
500491 }
501492
502493 /**
@@ -559,4 +550,18 @@ private static function parse_bunny_timestamp(string $timestamp): int
559550 {
560551 return (date_create_from_format ('Y-m-d\TH:i:s.u ' , $ timestamp ) ?: date_create_from_format ('Y-m-d\TH:i:s ' , $ timestamp ))->getTimestamp ();
561552 }
553+
554+ private function exists (string $ type , string $ path ): bool
555+ {
556+ $ list = new DirectoryListing ($ this ->listContents (
557+ Util::splitPathIntoDirectoryAndFile ($ path )['dir ' ],
558+ false
559+ ));
560+
561+ $ count = $ list ->filter (function (StorageAttributes $ item ) use ($ path , $ type ) {
562+ return $ item ->type () === $ type && Util::normalizePath ($ item ->path ()) === Util::normalizePath ($ path );
563+ })->toArray ();
564+
565+ return (bool ) count ($ count );
566+ }
562567}
0 commit comments