Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Checksums for filesystem disks #44660

Merged
merged 4 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Filesystem/FilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}
}