Skip to content

Commit

Permalink
Merge pull request #8100 from nextcloud/s3-folder-delete
Browse files Browse the repository at this point in the history
Fix deleting folders when using s3 external storage
  • Loading branch information
MorrisJobke authored Feb 8, 2018
2 parents d767d01 + 84bd2b6 commit 12c9bad
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions apps/files_external/lib/Lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private function invalidateCache($key) {
$keys = array_keys($this->objectCache->getData());
$keyLength = strlen($key);
foreach ($keys as $existingKey) {
if (substr($existingKey, 0, $keyLength) === $keys) {
if (substr($existingKey, 0, $keyLength) === $key) {
unset($this->objectCache[$existingKey]);
}
}
Expand Down Expand Up @@ -242,17 +242,22 @@ private function batchDelete($path = null) {
$params['Prefix'] = $path . '/';
}
try {
$connection = $this->getConnection();
// Since there are no real directories on S3, we need
// to delete all objects prefixed with the path.
do {
// instead of the iterator, manually loop over the list ...
$objects = $this->getConnection()->listObjects($params);
$objects = $connection->listObjects($params);
// ... so we can delete the files in batches
$this->getConnection()->deleteObjects(array(
'Bucket' => $this->bucket,
'Objects' => $objects['Contents']
));
$this->testTimeout();
if (isset($objects['Contents'])) {
$connection->deleteObjects([
'Bucket' => $this->bucket,
'Delete' => [
'Objects' => $objects['Contents']
]
]);
$this->testTimeout();
}
// we reached the end when the list is no longer truncated
} while ($objects['IsTruncated']);
} catch (S3Exception $e) {
Expand Down

0 comments on commit 12c9bad

Please sign in to comment.