From 720b499cf4ed7d1bc0b48b7c953ff59deca8fafc Mon Sep 17 00:00:00 2001 From: jojoliang Date: Thu, 8 Jul 2021 15:11:55 +0800 Subject: [PATCH] update ctx --- object.go | 12 ++++++------ object_part.go | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/object.go b/object.go index bf0cd6e..bd836df 100644 --- a/object.go +++ b/object.go @@ -667,7 +667,7 @@ func (drc *DiscardReadCloser) Close() error { return nil } -func worker(s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) { +func worker(ctx context.Context, s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) { for j := range jobs { j.Opt.ContentLength = j.Chunk.Size @@ -684,7 +684,7 @@ func worker(s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) { break } fd.Seek(j.Chunk.OffSet, os.SEEK_SET) - resp, err := s.UploadPart(context.Background(), j.Name, j.UploadId, j.Chunk.Number, + resp, err := s.UploadPart(ctx, j.Name, j.UploadId, j.Chunk.Number, LimitReadCloser(fd, j.Chunk.Size), j.Opt) res.PartNumber = j.Chunk.Number res.Resp = resp @@ -703,7 +703,7 @@ func worker(s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) { } } -func downloadWorker(s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) { +func downloadWorker(ctx context.Context, s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) { for j := range jobs { opt := &RangeOptions{ HasStart: true, @@ -716,7 +716,7 @@ func downloadWorker(s *ObjectService, jobs <-chan *Jobs, results chan<- *Results for { var res Results res.PartNumber = j.Chunk.Number - resp, err := s.Get(context.Background(), j.Name, j.DownOpt, j.VersionId...) + resp, err := s.Get(ctx, j.Name, j.DownOpt, j.VersionId...) res.err = err res.Resp = resp if err != nil { @@ -972,7 +972,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string // 3.Start worker for w := 1; w <= poolSize; w++ { - go worker(s, chjobs, chresults) + go worker(ctx, s, chjobs, chresults) } // progress started event @@ -1241,7 +1241,7 @@ func (s *ObjectService) Download(ctx context.Context, name string, filepath stri chjobs := make(chan *Jobs, 100) chresults := make(chan *Results, 10000) for w := 1; w <= poolSize; w++ { - go downloadWorker(s, chjobs, chresults) + go downloadWorker(ctx, s, chjobs, chresults) } go func() { diff --git a/object_part.go b/object_part.go index 2a94675..4ab97f2 100644 --- a/object_part.go +++ b/object_part.go @@ -353,13 +353,13 @@ type CopyResults struct { res *CopyPartResult } -func copyworker(s *ObjectService, jobs <-chan *CopyJobs, results chan<- *CopyResults) { +func copyworker(ctx context.Context, s *ObjectService, jobs <-chan *CopyJobs, results chan<- *CopyResults) { for j := range jobs { var copyres CopyResults j.Opt.XCosCopySourceRange = fmt.Sprintf("bytes=%d-%d", j.Chunk.OffSet, j.Chunk.OffSet+j.Chunk.Size-1) rt := j.RetryTimes for { - res, resp, err := s.CopyPart(context.Background(), j.Name, j.UploadId, j.Chunk.Number, j.Opt.XCosCopySource, j.Opt) + res, resp, err := s.CopyPart(ctx, j.Name, j.UploadId, j.Chunk.Number, j.Opt.XCosCopySource, j.Opt) copyres.PartNumber = j.Chunk.Number copyres.Resp = resp copyres.err = err @@ -456,7 +456,7 @@ func (s *ObjectService) MultiCopy(ctx context.Context, name string, sourceURL st optcom := &CompleteMultipartUploadOptions{} for w := 1; w <= poolSize; w++ { - go copyworker(s, chjobs, chresults) + go copyworker(ctx, s, chjobs, chresults) } go func() {