2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-03 09:30:50 +00:00

backend/sema: rename type to connectionLimitedBackend

This commit is contained in:
Michael Eischer 2023-04-21 22:44:45 +02:00
parent 6042df075f
commit f27750e270

View File

@ -9,30 +9,30 @@ import (
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
) )
// make sure that SemaphoreBackend implements restic.Backend // make sure that connectionLimitedBackend implements restic.Backend
var _ restic.Backend = &SemaphoreBackend{} var _ restic.Backend = &connectionLimitedBackend{}
// SemaphoreBackend limits the number of concurrent operations. // connectionLimitedBackend limits the number of concurrent operations.
type SemaphoreBackend struct { type connectionLimitedBackend struct {
restic.Backend restic.Backend
sem semaphore sem semaphore
} }
// New creates a backend that limits the concurrent operations on the underlying backend // New creates a backend that limits the concurrent operations on the underlying backend
func New(be restic.Backend) *SemaphoreBackend { func New(be restic.Backend) restic.Backend {
sem, err := newSemaphore(be.Connections()) sem, err := newSemaphore(be.Connections())
if err != nil { if err != nil {
panic(err) panic(err)
} }
return &SemaphoreBackend{ return &connectionLimitedBackend{
Backend: be, Backend: be,
sem: sem, sem: sem,
} }
} }
// Save adds new Data to the backend. // Save adds new Data to the backend.
func (be *SemaphoreBackend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error { func (be *connectionLimitedBackend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error {
if err := h.Valid(); err != nil { if err := h.Valid(); err != nil {
return backoff.Permanent(err) return backoff.Permanent(err)
} }
@ -45,7 +45,7 @@ func (be *SemaphoreBackend) Save(ctx context.Context, h restic.Handle, rd restic
// Load runs fn with a reader that yields the contents of the file at h at the // Load runs fn with a reader that yields the contents of the file at h at the
// given offset. // given offset.
func (be *SemaphoreBackend) Load(ctx context.Context, h restic.Handle, length int, offset int64, fn func(rd io.Reader) error) error { func (be *connectionLimitedBackend) Load(ctx context.Context, h restic.Handle, length int, offset int64, fn func(rd io.Reader) error) error {
if err := h.Valid(); err != nil { if err := h.Valid(); err != nil {
return backoff.Permanent(err) return backoff.Permanent(err)
} }
@ -63,7 +63,7 @@ func (be *SemaphoreBackend) Load(ctx context.Context, h restic.Handle, length in
} }
// Stat returns information about a file in the backend. // Stat returns information about a file in the backend.
func (be *SemaphoreBackend) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, error) { func (be *connectionLimitedBackend) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, error) {
if err := h.Valid(); err != nil { if err := h.Valid(); err != nil {
return restic.FileInfo{}, backoff.Permanent(err) return restic.FileInfo{}, backoff.Permanent(err)
} }
@ -75,7 +75,7 @@ func (be *SemaphoreBackend) Stat(ctx context.Context, h restic.Handle) (restic.F
} }
// Remove deletes a file from the backend. // Remove deletes a file from the backend.
func (be *SemaphoreBackend) Remove(ctx context.Context, h restic.Handle) error { func (be *connectionLimitedBackend) Remove(ctx context.Context, h restic.Handle) error {
if err := h.Valid(); err != nil { if err := h.Valid(); err != nil {
return backoff.Permanent(err) return backoff.Permanent(err)
} }
@ -86,6 +86,6 @@ func (be *SemaphoreBackend) Remove(ctx context.Context, h restic.Handle) error {
return be.Backend.Remove(ctx, h) return be.Backend.Remove(ctx, h)
} }
func (be *SemaphoreBackend) Unwrap() restic.Backend { func (be *connectionLimitedBackend) Unwrap() restic.Backend {
return be.Backend return be.Backend
} }