From 308ea83cc0d82da350137760ad6b8b7133d5b16d Mon Sep 17 00:00:00 2001 From: Moritz Bechler Date: Mon, 13 Nov 2017 14:48:25 +0100 Subject: [PATCH] S3 backend: include path prefix in removal requests. DELETE requests, both for temporary files and no longer referenced packages, lacked the configured path prefix and therefor were not removed if a prefix is configured. --- s3/public.go | 4 ++-- s3/public_test.go | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/s3/public.go b/s3/public.go index bb97f3251..e8f5e4941 100644 --- a/s3/public.go +++ b/s3/public.go @@ -183,12 +183,12 @@ func (storage *PublishedStorage) putFile(path string, source io.ReadSeeker) erro func (storage *PublishedStorage) Remove(path string) error { params := &s3.DeleteObjectInput{ Bucket: aws.String(storage.bucket), - Key: aws.String(path), + Key: aws.String(filepath.Join(storage.prefix,path)), } _, err := storage.s3.DeleteObject(params) if err != nil { return errors.Wrap(err, fmt.Sprintf("error deleting %s from %s", path, storage)) - } + } if storage.plusWorkaround && strings.Contains(path, "+") { // try to remove workaround version, but don't care about result diff --git a/s3/public_test.go b/s3/public_test.go index 354c66683..7339ac4ad 100644 --- a/s3/public_test.go +++ b/s3/public_test.go @@ -160,6 +160,13 @@ func (s *PublishedStorageSuite) TestRemove(c *C) { c.Check(err, IsNil) s.AssertNoFile(c, "a/b") + + s.PutFile(c, "lala/xyz", []byte("test")) + + errp := s.prefixedStorage.Remove("xyz") + c.Check(errp, IsNil) + + s.AssertNoFile(c, "lala/xyz") } func (s *PublishedStorageSuite) TestRemovePlusWorkaround(c *C) {