Skip to content
Snippets Groups Projects
Commit 4886c858 authored by Robin Appelman's avatar Robin Appelman
Browse files

Merge pull request #9529 from helmutschneider/fix-8326

Fixes #8326: deletion of directories on S3
parents 6cbfe8fd ac75a245
Branches
No related tags found
No related merge requests found
...@@ -190,26 +190,17 @@ class AmazonS3 extends \OC\Files\Storage\Common { ...@@ -190,26 +190,17 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return false; return false;
} }
$dh = $this->opendir($path); // Since there are no real directories on S3, we need
// to delete all objects prefixed with the path.
if(is_resource($dh)) { $objects = $this->connection->listObjects(array(
while (($file = readdir($dh)) !== false) { 'Bucket' => $this->bucket,
if ($file === '.' || $file === '..') { 'Prefix' => $path . '/'
continue; ));
}
if ($this->is_dir($path . '/' . $file)) {
$this->rmdir($path . '/' . $file);
} else {
$this->unlink($path . '/' . $file);
}
}
}
try { try {
$result = $this->connection->deleteObject(array( $result = $this->connection->deleteObjects(array(
'Bucket' => $this->bucket, 'Bucket' => $this->bucket,
'Key' => $path . '/' 'Objects' => $objects['Contents']
)); ));
$this->testTimeout(); $this->testTimeout();
} catch (S3Exception $e) { } catch (S3Exception $e) {
...@@ -310,6 +301,10 @@ class AmazonS3 extends \OC\Files\Storage\Common { ...@@ -310,6 +301,10 @@ class AmazonS3 extends \OC\Files\Storage\Common {
public function unlink($path) { public function unlink($path) {
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if ( $this->is_dir($path) ) {
return $this->rmdir($path);
}
try { try {
$result = $this->connection->deleteObject(array( $result = $this->connection->deleteObject(array(
'Bucket' => $this->bucket, 'Bucket' => $this->bucket,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment