Skip to content

Commit dc4f925

Browse files
liubinwy65701436
authored andcommitted
fix: check blob exist before copying layers samller than chunk size (goharbor#21883)
`copyBlobByChunk()` should like `copyBlob()`, first try to mount an exists layer, if not mounted or exist, then copy the layer monolithic or by chunks. Signed-off-by: Bin Liu <[email protected]> Signed-off-by: Bin Liu <[email protected]>
1 parent 56bda80 commit dc4f925

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/controller/replication/transfer/image/transfer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,6 @@ func (t *transfer) copyBlobByMonolithic(srcRepo, dstRepo, digest string, sizeFro
403403
// copyBlobByChunk copy blob by chunk with specified start and end range.
404404
// The <range> refers to the byte range of the chunk, and MUST be inclusive on both ends. The first chunk's range MUST begin with 0.
405405
func (t *transfer) copyBlobByChunk(srcRepo, dstRepo, digest string, sizeFromDescriptor int64, start, end *int64, location *string, speed int32) error {
406-
// fallback to copy by monolithic if the blob size is equal or less than chunk size.
407-
if sizeFromDescriptor <= replicationChunkSize {
408-
return t.copyBlobByMonolithic(srcRepo, dstRepo, digest, sizeFromDescriptor, speed)
409-
}
410-
411406
mounted, err := t.tryMountBlob(srcRepo, dstRepo, digest)
412407
if err != nil {
413408
return err
@@ -417,6 +412,11 @@ func (t *transfer) copyBlobByChunk(srcRepo, dstRepo, digest string, sizeFromDesc
417412
return nil
418413
}
419414

415+
// fallback to copy by monolithic if the blob size is equal or less than chunk size.
416+
if sizeFromDescriptor <= replicationChunkSize {
417+
return t.copyBlobByMonolithic(srcRepo, dstRepo, digest, sizeFromDescriptor, speed)
418+
}
419+
420420
// end range should equal (blobSize - 1)
421421
endRange := sizeFromDescriptor - 1
422422
for {

0 commit comments

Comments
 (0)