@@ -355,7 +355,7 @@ type CopyPartResult struct {
355355// 当传入uploadID和partNumber都相同的时候,后传入的块将覆盖之前传入的块。当uploadID不存在时会返回404错误,NoSuchUpload.
356356//
357357// https://www.qcloud.com/document/product/436/7750
358- func (s * ObjectService ) CopyPart (ctx context.Context , name , uploadID string , partNumber int , sourceURL string , opt * ObjectCopyPartOptions ) (* CopyPartResult , * Response , error ) {
358+ func (s * ObjectService ) CopyPart (ctx context.Context , name , uploadID string , partNumber int , sourceURL string , opt * ObjectCopyPartOptions , id ... string ) (* CopyPartResult , * Response , error ) {
359359 if strings .HasPrefix (sourceURL , "http://" ) || strings .HasPrefix (sourceURL , "https://" ) {
360360 return nil , nil , errors .New ("sourceURL format is invalid." )
361361 }
@@ -364,11 +364,17 @@ func (s *ObjectService) CopyPart(ctx context.Context, name, uploadID string, par
364364 return nil , nil , errors .New (fmt .Sprintf ("x-cos-copy-source format error: %s" , sourceURL ))
365365 }
366366 var u string
367- keyAndVer := strings .SplitN (surl [1 ], "?" , 2 )
368- if len (keyAndVer ) < 2 {
369- u = fmt .Sprintf ("%s/%s" , surl [0 ], encodeURIComponent (surl [1 ], []byte {'/' }))
367+ if len (id ) == 1 {
368+ u = fmt .Sprintf ("%s/%s?versionId=%s" , surl [0 ], encodeURIComponent (surl [1 ]), id [0 ])
369+ } else if len (id ) == 0 {
370+ keyAndVer := strings .SplitN (surl [1 ], "?versionId=" , 2 )
371+ if len (keyAndVer ) < 2 {
372+ u = fmt .Sprintf ("%s/%s" , surl [0 ], encodeURIComponent (surl [1 ], []byte {'/' }))
373+ } else {
374+ u = fmt .Sprintf ("%v/%v?versionId=%v" , surl [0 ], encodeURIComponent (keyAndVer [0 ], []byte {'/' }), encodeURIComponent (keyAndVer [1 ], []byte {'=' }))
375+ }
370376 } else {
371- u = fmt . Sprintf ( "%v/%v?%v" , surl [ 0 ], encodeURIComponent ( keyAndVer [ 0 ], [] byte { '/' }), encodeURIComponent ( keyAndVer [ 1 ], [] byte { '=' }) )
377+ return nil , nil , errors . New ( "wrong params" )
372378 }
373379
374380 opt = cloneObjectCopyPartOptions (opt )
@@ -461,6 +467,7 @@ type CopyJobs struct {
461467 RetryTimes int
462468 Chunk Chunk
463469 Opt * ObjectCopyPartOptions
470+ Ids []string
464471}
465472
466473type CopyResults struct {
@@ -476,7 +483,7 @@ func copyworker(ctx context.Context, s *ObjectService, jobs <-chan *CopyJobs, re
476483 j .Opt .XCosCopySourceRange = fmt .Sprintf ("bytes=%d-%d" , j .Chunk .OffSet , j .Chunk .OffSet + j .Chunk .Size - 1 )
477484 rt := j .RetryTimes
478485 for {
479- res , resp , err := s .CopyPart (ctx , j .Name , j .UploadId , j .Chunk .Number , j .Opt .XCosCopySource , j .Opt )
486+ res , resp , err := s .CopyPart (ctx , j .Name , j .UploadId , j .Chunk .Number , j .Opt .XCosCopySource , j .Opt , j . Ids ... )
480487 copyres .PartNumber = j .Chunk .Number
481488 copyres .Resp = resp
482489 copyres .err = err
@@ -500,7 +507,7 @@ func copyworker(ctx context.Context, s *ObjectService, jobs <-chan *CopyJobs, re
500507 }
501508}
502509
503- func (s * ObjectService ) innerHead (ctx context.Context , sourceURL string , opt * ObjectHeadOptions , id []string ) (* Response , error ) {
510+ func (s * ObjectService ) innerHead (ctx context.Context , sourceURL string , id []string ) (* Response , error ) {
504511 surl := strings .SplitN (sourceURL , "/" , 2 )
505512 if len (surl ) < 2 {
506513 return nil , fmt .Errorf ("sourceURL format error: %s" , sourceURL )
@@ -517,12 +524,12 @@ func (s *ObjectService) innerHead(ctx context.Context, sourceURL string, opt *Ob
517524 if len (id ) > 0 {
518525 return client .Object .Head (ctx , surl [1 ], nil , id [0 ])
519526 } else {
520- keyAndVer := strings .SplitN (surl [1 ], "?" , 2 )
527+ keyAndVer := strings .SplitN (surl [1 ], "?versionId= " , 2 )
521528 if len (keyAndVer ) < 2 {
522529 // 不存在versionId
523530 return client .Object .Head (ctx , surl [1 ], nil )
524531 } else {
525- q , err := url .ParseQuery (keyAndVer [1 ])
532+ q , err := url .ParseQuery ("versionId=" + keyAndVer [1 ])
526533 if err != nil {
527534 return nil , fmt .Errorf ("sourceURL format error: %s" , sourceURL )
528535 }
@@ -538,17 +545,13 @@ func (s *ObjectService) MultiCopy(ctx context.Context, name string, sourceURL st
538545 return nil , nil , errors .New ("sourceURL format is invalid." )
539546 }
540547
541- resp , err := s .innerHead (ctx , sourceURL , nil , id )
548+ resp , err := s .innerHead (ctx , sourceURL , id )
542549 if err != nil {
543550 return nil , nil , err
544551 }
545552 totalBytes := resp .ContentLength
546- var u string
547- if len (id ) == 1 {
548- u = fmt .Sprintf ("%s?versionId=%s" , sourceURL , id [0 ])
549- } else if len (id ) == 0 {
550- u = sourceURL
551- } else {
553+ u := sourceURL
554+ if len (id ) > 1 {
552555 return nil , nil , errors .New ("wrong params" )
553556 }
554557
@@ -610,6 +613,7 @@ func (s *ObjectService) MultiCopy(ctx context.Context, name string, sourceURL st
610613 UploadId : uploadID ,
611614 Chunk : chunk ,
612615 Opt : partOpt ,
616+ Ids : id ,
613617 }
614618 chjobs <- job
615619 }
0 commit comments