From 8bbfc538f14c529d9d7d3fba86b1867ed9f0513d Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Thu, 25 Oct 2018 16:39:41 +0200 Subject: [PATCH] AWS: Ensure that the order returned by ListObjects is consistent When a backup is deleted, the delete method uses ListObjects to get a list of files it needs to delete in s3. Different s3 implementations may return the object lists in different, even non-deterministic orders, which can result in the deletion not working because ark tries to delete a non empty folder before it tries to delete the files in the folder. Signed-off-by: Bastian Hofmann --- pkg/cloudprovider/aws/object_store.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/cloudprovider/aws/object_store.go b/pkg/cloudprovider/aws/object_store.go index 0bb074cfa..2c956f428 100644 --- a/pkg/cloudprovider/aws/object_store.go +++ b/pkg/cloudprovider/aws/object_store.go @@ -18,6 +18,7 @@ package aws import ( "io" + "sort" "strconv" "time" @@ -187,6 +188,11 @@ func (o *objectStore) ListObjects(bucket, prefix string) ([]string, error) { return nil, errors.WithStack(err) } + // ensure that returned objects are in a consistent order so that the deletion logic deletes the objects before + // the pseudo-folder prefix object for s3 providers (such as Quobyte) that return the pseudo-folder as an object. + // See https://github.com/heptio/ark/pull/999 + sort.Sort(sort.Reverse(sort.StringSlice(ret))) + return ret, nil }