Skip to content

Commit

Permalink
Fix deletion of files without extension (#3664)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaconnier authored Jul 15, 2024
1 parent b091d25 commit 38174fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Support/FileRemover/DefaultFileRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function removeFromMediaDirectory(Media $media, string $disk): void
$imagePaths = array_filter(
$allFilePaths,
function (string $path) use ($media) {
return Str::contains($path, pathinfo($media->file_name, PATHINFO_FILENAME).'.');
return Str::afterLast($path, '/') === $media->file_name;
}
);
foreach ($imagePaths as $imagePath) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Feature/Media/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
expect(File::isDirectory($this->getMediaDirectory($media->id)))->toBeFalse();
});

it('will remove the files without extension', function () {
$media = $this->testModel->addMedia($this->getTestImageWithoutExtension())->toMediaCollection('images');

expect(File::isDirectory($this->getMediaDirectory($media->id)))->toBeTrue();

$media->delete();

expect(File::isDirectory($this->getMediaDirectory($media->id)))->toBeFalse();
});

it('will remove files when deleting a media object with a custom path generator', function () {
config(['media-library.path_generator' => TestPathGenerator::class]);

Expand Down

0 comments on commit 38174fd

Please sign in to comment.