Merge pull request #8466 from dmcgowan/fix-transfer-default-limiters

[transfer] avoid setting limiters when max is 0
This commit is contained in:
Phil Estes 2023-05-03 06:52:29 -07:00 committed by GitHub
commit be2ca3c860
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,14 +46,19 @@ type localTransferService struct {
} }
func NewTransferService(lm leases.Manager, cs content.Store, is images.Store, tc *TransferConfig) transfer.Transferrer { func NewTransferService(lm leases.Manager, cs content.Store, is images.Store, tc *TransferConfig) transfer.Transferrer {
return &localTransferService{ ts := &localTransferService{
leases: lm, leases: lm,
content: cs, content: cs,
images: is, images: is,
limiterU: semaphore.NewWeighted(int64(tc.MaxConcurrentUploadedLayers)), config: *tc,
limiterD: semaphore.NewWeighted(int64(tc.MaxConcurrentDownloads)),
config: *tc,
} }
if tc.MaxConcurrentUploadedLayers > 0 {
ts.limiterU = semaphore.NewWeighted(int64(tc.MaxConcurrentUploadedLayers))
}
if tc.MaxConcurrentDownloads > 0 {
ts.limiterD = semaphore.NewWeighted(int64(tc.MaxConcurrentDownloads))
}
return ts
} }
func (ts *localTransferService) Transfer(ctx context.Context, src interface{}, dest interface{}, opts ...transfer.Opt) error { func (ts *localTransferService) Transfer(ctx context.Context, src interface{}, dest interface{}, opts ...transfer.Opt) error {