From 5e69c19d3450d06c3da270ca12e43647432d0ca4 Mon Sep 17 00:00:00 2001 From: jojoliang Date: Wed, 22 Jul 2020 15:59:30 +0800 Subject: [PATCH] fix list uploads --- example/object/list_uploads.go | 1 - object.go | 30 +++++++++++++----------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/example/object/list_uploads.go b/example/object/list_uploads.go index f2bf8aa..86d74c4 100644 --- a/example/object/list_uploads.go +++ b/example/object/list_uploads.go @@ -76,7 +76,6 @@ func main() { name := "test/test_list_parts.go" up := initUpload(c, name) uploadID := up.UploadID - ctx := context.Background() blockSize := 1024 * 1024 * 3 for i := 1; i < 5; i++ { diff --git a/object.go b/object.go index 1cea83f..787c382 100644 --- a/object.go +++ b/object.go @@ -635,7 +635,6 @@ func (s *ObjectService) getResumableUploadID(ctx context.Context, name string) ( } func (s *ObjectService) checkUploadedParts(ctx context.Context, name, UploadID, filepath string, chunks []Chunk, partNum int) error { - var err error var uploadedParts []Object isTruncated := true opt := &ObjectListPartsOptions{ @@ -657,34 +656,31 @@ func (s *ObjectService) checkUploadedParts(ctx context.Context, name, UploadID, return err } defer fd.Close() - err = nil + // 某个分块出错, 重置chunks + ret := func(e error) error { + for _, chunk := range chunks { + chunk.Done = false + } + return e + } for _, part := range uploadedParts { partNumber := part.PartNumber if partNumber > partNum { - err = errors.New("Part Number is not consistent") - break + return ret(errors.New("Part Number is not consistent")) } partNumber = partNumber - 1 fd.Seek(chunks[partNumber].OffSet, os.SEEK_SET) - bs, e := ioutil.ReadAll(io.LimitReader(fd, chunks[partNumber].Size)) - if e != nil { - err = e - break + bs, err := ioutil.ReadAll(io.LimitReader(fd, chunks[partNumber].Size)) + if err != nil { + return ret(err) } localMD5 := fmt.Sprintf("\"%x\"", md5.Sum(bs)) if localMD5 != part.ETag { - err = errors.New(fmt.Sprintf("CheckSum Failed in Part[%d]", part.PartNumber)) - break + return ret(errors.New(fmt.Sprintf("CheckSum Failed in Part[%d]", part.PartNumber))) } chunks[partNumber].Done = true } - // 某个分块出错, 重置chunks - if err != nil { - for _, chunk := range chunks { - chunk.Done = false - } - } - return err + return nil } // MultiUpload/Upload 为高级upload接口,并发分块上传