From 7afd77604eeca78d82a15d57c22716c5e4850cc7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 29 Jan 2018 15:06:10 +0100 Subject: [PATCH 1/2] adjust s3 bulk delete to new sdk syntax Signed-off-by: Robin Appelman --- .../files_external/lib/Lib/Storage/AmazonS3.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index 03a24e8976..efcae431f9 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -242,17 +242,22 @@ class AmazonS3 extends \OC\Files\Storage\Common { $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) { From 84bd2b6bc910174ee87d7dcbfc767de05a5a22a5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 29 Jan 2018 15:09:15 +0100 Subject: [PATCH 2/2] fix invalidating folder cache for s3 Signed-off-by: Robin Appelman --- apps/files_external/lib/Lib/Storage/AmazonS3.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index efcae431f9..f06247c369 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -101,7 +101,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { $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]); } }