Skip to content

Commit

Permalink
fix deletion and list on UFile (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
davies committed Mar 8, 2021
1 parent a7e2431 commit f4f5f53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/object/restful.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (s *RestfulStorage) Delete(key string) error {
return err
}
defer cleanup(resp)
if resp.StatusCode != 204 {
if resp.StatusCode != 204 && resp.StatusCode != 404 {
return parseError(resp)
}
return nil
Expand Down
17 changes: 12 additions & 5 deletions pkg/object/ufile.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,20 @@ func (u *ufile) Create() error {

func (u *ufile) parseResp(resp *http.Response, out interface{}) error {
defer resp.Body.Close()
var data []byte
if resp.ContentLength <= 0 || resp.ContentLength > (1<<31) {
return fmt.Errorf("invalid content length: %d", resp.ContentLength)
}
data := make([]byte, resp.ContentLength)
if _, err := io.ReadFull(resp.Body, data); err != nil {
return err
d, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
data = d
} else {
data = make([]byte, resp.ContentLength)
if _, err := io.ReadFull(resp.Body, data); err != nil {
return err
}
}

if resp.StatusCode != 200 {
return fmt.Errorf("status: %v, message: %s", resp.StatusCode, string(data))
}
Expand Down

0 comments on commit f4f5f53

Please sign in to comment.