diff --git a/composer.json b/composer.json index 2e27ac05c6b4..97280b8aa19f 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "fruitcake/php-cors": "^1.2", "laravel/serializable-closure": "^1.2.2", "league/commonmark": "^2.2", - "league/flysystem": "^3.0.16", + "league/flysystem": "^3.8.0", "monolog/monolog": "^2.0", "nesbot/carbon": "^2.62.1", "nunomaduro/termwind": "^1.13", diff --git a/src/Illuminate/Filesystem/FilesystemAdapter.php b/src/Illuminate/Filesystem/FilesystemAdapter.php index 91ea80259205..e484321c6ea2 100644 --- a/src/Illuminate/Filesystem/FilesystemAdapter.php +++ b/src/Illuminate/Filesystem/FilesystemAdapter.php @@ -24,6 +24,7 @@ use League\Flysystem\UnableToDeleteDirectory; use League\Flysystem\UnableToDeleteFile; use League\Flysystem\UnableToMoveFile; +use League\Flysystem\UnableToProvideChecksum; use League\Flysystem\UnableToReadFile; use League\Flysystem\UnableToRetrieveMetadata; use League\Flysystem\UnableToSetVisibility; @@ -554,6 +555,24 @@ public function size($path) return $this->driver->fileSize($path); } + /** + * Get the checksum for a file. + * + * @return string|false + * + * @throws UnableToProvideChecksum + */ + public function checksum(string $path, array $options = []): string|false + { + try { + return $this->driver->checksum($path, $options); + } catch (UnableToProvideChecksum $e) { + throw_if($this->throwsExceptions(), $e); + + return false; + } + } + /** * Get the mime-type of a given file. * diff --git a/tests/Filesystem/FilesystemAdapterTest.php b/tests/Filesystem/FilesystemAdapterTest.php index e0d045d38e06..80d4d5fbc936 100644 --- a/tests/Filesystem/FilesystemAdapterTest.php +++ b/tests/Filesystem/FilesystemAdapterTest.php @@ -571,4 +571,13 @@ public function testPrefixesUrls() $this->assertEquals('https://example.org/images/picture.jpeg', $filesystemAdapter->url('picture.jpeg')); } + + public function testGetChecksum() + { + $filesystemAdapter = new FilesystemAdapter($this->filesystem, $this->adapter); + $filesystemAdapter->write('path.txt', 'contents of file'); + + $this->assertEquals('730bed78bccf58c2cfe44c29b71e5e6b', $filesystemAdapter->checksum('path.txt')); + $this->assertEquals('a5c3556d', $filesystemAdapter->checksum('path.txt', ['checksum_algo' => 'crc32'])); + } }