From da0cb14ab88b61c1c5cb2efc5d7f0cb32abfb1d6 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 8 Apr 2011 23:22:52 -0700 Subject: [PATCH] Amazon: untested delete support --- lib/go/camli/blobserver/s3/remove.go | 10 +++++++++- lib/go/camli/misc/amazon/s3/client.go | 21 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/go/camli/blobserver/s3/remove.go b/lib/go/camli/blobserver/s3/remove.go index acc9f9b66..dd2917bc8 100644 --- a/lib/go/camli/blobserver/s3/remove.go +++ b/lib/go/camli/blobserver/s3/remove.go @@ -27,6 +27,14 @@ import ( var _ = log.Printf func (sto *s3Storage) Remove(partition blobserver.Partition, blobs []*blobref.BlobRef) os.Error { - return os.NewError("NOIMPL") + // TODO: do these in parallel + var reterr os.Error + for _, blob := range blobs { + if err := sto.s3Client.Delete(sto.bucket, blob.String()); err != nil { + reterr = err + } + } + return reterr + } diff --git a/lib/go/camli/misc/amazon/s3/client.go b/lib/go/camli/misc/amazon/s3/client.go index 438e27759..af37bd6a8 100644 --- a/lib/go/camli/misc/amazon/s3/client.go +++ b/lib/go/camli/misc/amazon/s3/client.go @@ -175,8 +175,27 @@ func (c *Client) Get(bucket, key string) (body io.ReadCloser, size int64, err os return } if res.StatusCode != http.StatusOK { - err = fmt.Errorf("Amazon HTTP error on GET: %d", res.Status) + err = fmt.Errorf("Amazon HTTP error on GET: %d", res.StatusCode) return } return res.Body, res.ContentLength, nil } + +func (c *Client) Delete(bucket, key string) os.Error { + url := fmt.Sprintf("http://%s.s3.amazonaws.com/%s", bucket, key) + req := newReq(url) + req.Method = "DELETE" + c.Auth.SignRequest(req) + res, err := c.httpClient().Do(req) + if err != nil { + return err + } + if res != nil && res.Body != nil { + defer res.Body.Close() + } + if res.StatusCode == http.StatusNotFound || res.StatusCode == http.StatusNoContent || + res.StatusCode == http.StatusOK { + return nil + } + return fmt.Errorf("Amazon HTTP error on DELETE: %d", res.StatusCode) +}