Skip to content

Commit

Permalink
Merge pull request #22 from jeroenlammerts/master
Browse files Browse the repository at this point in the history
Fix deleteDir removes other files/dirs #19
  • Loading branch information
chrisnharvey authored Dec 6, 2020
2 parents 63cf62d + cd02e4b commit 41e3ea0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/SwiftAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ public function delete($path)
*/
public function deleteDir($dirname)
{
// Make sure a slash is added to the end.
$dirname = rtrim(trim($dirname), '/') . '/';

// To be safe, don't delete everything.
if($dirname === '/') {
return false;
}

$objects = $this->container->listObjects([
'prefix' => $this->applyPathPrefix($dirname)
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/SwiftAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testDeleteDir()
$this->container->shouldReceive('listObjects')
->once()
->with([
'prefix' => 'hello'
'prefix' => 'hello/'
])
->andReturn($objects);

Expand Down

0 comments on commit 41e3ea0

Please sign in to comment.