Skip to content

Commit 12c9bad

Browse files
authored
Merge pull request #8100 from nextcloud/s3-folder-delete
Fix deleting folders when using s3 external storage
2 parents d767d01 + 84bd2b6 commit 12c9bad

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

apps/files_external/lib/Lib/Storage/AmazonS3.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private function invalidateCache($key) {
101101
$keys = array_keys($this->objectCache->getData());
102102
$keyLength = strlen($key);
103103
foreach ($keys as $existingKey) {
104-
if (substr($existingKey, 0, $keyLength) === $keys) {
104+
if (substr($existingKey, 0, $keyLength) === $key) {
105105
unset($this->objectCache[$existingKey]);
106106
}
107107
}
@@ -242,17 +242,22 @@ private function batchDelete($path = null) {
242242
$params['Prefix'] = $path . '/';
243243
}
244244
try {
245+
$connection = $this->getConnection();
245246
// Since there are no real directories on S3, we need
246247
// to delete all objects prefixed with the path.
247248
do {
248249
// instead of the iterator, manually loop over the list ...
249-
$objects = $this->getConnection()->listObjects($params);
250+
$objects = $connection->listObjects($params);
250251
// ... so we can delete the files in batches
251-
$this->getConnection()->deleteObjects(array(
252-
'Bucket' => $this->bucket,
253-
'Objects' => $objects['Contents']
254-
));
255-
$this->testTimeout();
252+
if (isset($objects['Contents'])) {
253+
$connection->deleteObjects([
254+
'Bucket' => $this->bucket,
255+
'Delete' => [
256+
'Objects' => $objects['Contents']
257+
]
258+
]);
259+
$this->testTimeout();
260+
}
256261
// we reached the end when the list is no longer truncated
257262
} while ($objects['IsTruncated']);
258263
} catch (S3Exception $e) {

0 commit comments

Comments
 (0)