diff --git a/src/Local/LocalFilesystemAdapter.php b/src/Local/LocalFilesystemAdapter.php index ac0a693c9..24fe86967 100644 --- a/src/Local/LocalFilesystemAdapter.php +++ b/src/Local/LocalFilesystemAdapter.php @@ -367,6 +367,11 @@ public function mimeType(string $path): FileAttributes { $location = $this->prefixer->prefixPath($path); error_clear_last(); + + if ( ! is_file($location)) { + throw UnableToRetrieveMetadata::mimeType($location, 'No such file exists.'); + } + $mimeType = $this->mimeTypeDetector->detectMimeTypeFromFile($location); if ($mimeType === null) { diff --git a/src/Local/LocalFilesystemAdapterTest.php b/src/Local/LocalFilesystemAdapterTest.php index b6bc96107..f05f214fa 100644 --- a/src/Local/LocalFilesystemAdapterTest.php +++ b/src/Local/LocalFilesystemAdapterTest.php @@ -4,6 +4,7 @@ namespace League\Flysystem\Local; +use League\MimeTypeDetection\FinfoMimeTypeDetector; use const LOCK_EX; use League\Flysystem\AdapterTestUtilities\FilesystemAdapterTestCase; use League\Flysystem\Config; @@ -539,7 +540,10 @@ public function fetching_unknown_mime_type_of_a_file(): void public function not_being_able_to_get_mimetype(): void { $this->expectException(UnableToRetrieveMetadata::class); - $adapter = new LocalFilesystemAdapter(static::ROOT); + $adapter = new LocalFilesystemAdapter( + location: static::ROOT, + mimeTypeDetector: new FinfoMimeTypeDetector(), + ); $adapter->mimeType('flysystem.svg'); }