From 33d5718843464068bd0d78ec97faff5266ce7206 Mon Sep 17 00:00:00 2001 From: Govert Versluis Date: Sun, 23 Mar 2014 17:37:16 +0100 Subject: [PATCH] Added missing check for http.StatusOK in Stat. Also made checks for http.StatusOK / 200 uniform Change-Id: I8ef608dc098cdfd221a53be20801d7dcdcdf7655 --- pkg/misc/amazon/s3/client.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/misc/amazon/s3/client.go b/pkg/misc/amazon/s3/client.go index 9cebf4b27..88f6121b9 100644 --- a/pkg/misc/amazon/s3/client.go +++ b/pkg/misc/amazon/s3/client.go @@ -74,7 +74,7 @@ func (c *Client) Buckets() ([]*Bucket, error) { return nil, err } defer httputil.CloseBody(res.Body) - if res.StatusCode != 200 { + if res.StatusCode != http.StatusOK { return nil, fmt.Errorf("s3: Unexpected status code %d fetching bucket list", res.StatusCode) } return parseListAllMyBuckets(res.Body) @@ -105,10 +105,13 @@ func (c *Client) Stat(name, bucket string) (size int64, reterr error) { if res.Body != nil { defer res.Body.Close() } - if res.StatusCode == http.StatusNotFound { + switch res.StatusCode { + case http.StatusNotFound: return 0, os.ErrNotExist + case http.StatusOK: + return strconv.ParseInt(res.Header.Get("Content-Length"), 10, 64) } - return strconv.ParseInt(res.Header.Get("Content-Length"), 10, 64) + return 0, fmt.Errorf("s3: Unexpected status code %d statting object %v", res.StatusCode, name) } func (c *Client) PutObject(name, bucket string, md5 hash.Hash, size int64, body io.Reader) error { @@ -132,7 +135,7 @@ func (c *Client) PutObject(name, bucket string, md5 hash.Hash, size int64, body if err != nil { return err } - if res.StatusCode != 200 { + if res.StatusCode != http.StatusOK { res.Write(os.Stderr) return fmt.Errorf("Got response code %d from s3", res.StatusCode) } @@ -187,7 +190,7 @@ func (c *Client) ListBucket(bucket string, startAt string, maxKeys int) (items [ } return nil, err } - if res.StatusCode != 200 { + if res.StatusCode != http.StatusOK { err = fmt.Errorf("s3.enumerate: status code %v", res.StatusCode) } else { bres = listBucketResults{}