Skip to content

Commit

Permalink
feat: prevent delete operation from deleting all contents
Browse files Browse the repository at this point in the history
  • Loading branch information
tinect authored Dec 23, 2023
1 parent 7ebff18 commit 6f05405
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG_en-GB.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.1.1

* Feat: add dedicated check to prevent deletion of all directories, when shopware does send empty path

# 3.1.0

* Chore: Update config texts and store descriptions
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"storage"
],
"description": "This plugins allows you to use BunnyCdn as adapter for media",
"version": "3.1.0",
"version": "3.1.1",
"type": "shopware-platform-plugin",
"license": "mit",
"authors": [
Expand Down
12 changes: 11 additions & 1 deletion src/Adapter/Shopware6BunnyCdnAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Frosh\BunnycdnMediaStorage\Adapter;

use League\Flysystem\UnableToDeleteFile;
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNAdapter;
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNClient;
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNRegion;
Expand Down Expand Up @@ -44,6 +45,11 @@ public function __construct(array $config)
*/
public function delete($path): void
{
// if path is empty or ends with /, it's a directory.
if (empty($path) || \str_ends_with($path, '/')) {
throw UnableToDeleteFile::atLocation($path, 'Deletion of directories prevented.');
}

if ($this->neverDelete) {
return;
}
Expand All @@ -56,7 +62,11 @@ public function delete($path): void
*/
public function deleteDirectory(string $path): void
{
$this->delete(rtrim($path, '/') . '/');
if ($this->neverDelete) {
return;
}

parent::deleteDirectory($path);
}

/**
Expand Down

0 comments on commit 6f05405

Please sign in to comment.