Skip to content

Commit 09ab7a4

Browse files
committed
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 <vincent@nextcloud.com>
1 parent 4a1a9d6 commit 09ab7a4

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,35 @@ private function batchDelete($path = null) {
311311
$connection->deleteObjects([
312312
'Bucket' => $this->bucket,
313313
'Delete' => [
314-
'Objects' => $objects['Contents']
314+
'Objects' => $objects['Contents'],
315315
]
316316
]);
317317
$this->testTimeout();
318318
}
319319
// we reached the end when the list is no longer truncated
320320
} while ($objects['IsTruncated']);
321+
322+
do {
323+
// delete all contained versions and deletion markers
324+
$objects = $connection->listObjectVersions($params);
325+
if (isset($objects['Versions'])) {
326+
$connection->deleteObjects([
327+
'Bucket' => $this->bucket,
328+
'Delete' => [
329+
'Objects' => $objects['Versions'],
330+
]
331+
]);
332+
}
333+
if (isset($objects['DeleteMarkers'])) {
334+
$connection->deleteObjects([
335+
'Bucket' => $this->bucket,
336+
'Delete' => [
337+
'Objects' => $objects['DeleteMarkers'],
338+
]
339+
]);
340+
}
341+
// we reached the end when the list is no longer truncated
342+
} while ($objects['IsTruncated']);
321343
$this->deleteObject($path);
322344
} catch (S3Exception $e) {
323345
\OC::$server->getLogger()->logException($e, ['app' => 'files_external']);

0 commit comments

Comments
 (0)