mirror of https://github.com/perkeep/perkeep.git
Added missing check for http.StatusOK in Stat.
Also made checks for http.StatusOK / 200 uniform Change-Id: I8ef608dc098cdfd221a53be20801d7dcdcdf7655
This commit is contained in:
parent
bfe27edc7f
commit
33d5718843
|
@ -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{}
|
||||
|
|
Loading…
Reference in New Issue