From 09ab7a40fefea254df69217e11bf7cbfb60777e0 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 11 Oct 2021 13:45:02 +0200 Subject: [PATCH] Delete S3 versions in rmdir When deleting a complete folder in a bucket that has versioning enabled, also make sure to delete all associated versions and delete markers Signed-off-by: Vincent Petry --- .../lib/Lib/Storage/AmazonS3.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index 1bdd11e39bd..a6872f1dc3e 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -311,13 +311,35 @@ class AmazonS3 extends \OC\Files\Storage\Common { $connection->deleteObjects([ 'Bucket' => $this->bucket, 'Delete' => [ - 'Objects' => $objects['Contents'] + 'Objects' => $objects['Contents'], ] ]); $this->testTimeout(); } // we reached the end when the list is no longer truncated } while ($objects['IsTruncated']); + + do { + // delete all contained versions and deletion markers + $objects = $connection->listObjectVersions($params); + if (isset($objects['Versions'])) { + $connection->deleteObjects([ + 'Bucket' => $this->bucket, + 'Delete' => [ + 'Objects' => $objects['Versions'], + ] + ]); + } + if (isset($objects['DeleteMarkers'])) { + $connection->deleteObjects([ + 'Bucket' => $this->bucket, + 'Delete' => [ + 'Objects' => $objects['DeleteMarkers'], + ] + ]); + } + // we reached the end when the list is no longer truncated + } while ($objects['IsTruncated']); $this->deleteObject($path); } catch (S3Exception $e) { \OC::$server->getLogger()->logException($e, ['app' => 'files_external']); -- 2.39.5