mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:47:50 +00:00
backend: refactor backend Connections and HasAtomicReplace into Properties
This commit is contained in:
@@ -22,9 +22,8 @@ type Backend struct {
|
||||
DeleteFn func(ctx context.Context) error
|
||||
WarmupFn func(ctx context.Context, h []backend.Handle) ([]backend.Handle, error)
|
||||
WarmupWaitFn func(ctx context.Context, h []backend.Handle) error
|
||||
ConnectionsFn func() uint
|
||||
PropertiesFn func() backend.Properties
|
||||
HasherFn func() hash.Hash
|
||||
HasAtomicReplaceFn func() bool
|
||||
}
|
||||
|
||||
// NewBackend returns new mock Backend instance
|
||||
@@ -42,12 +41,15 @@ func (m *Backend) Close() error {
|
||||
return m.CloseFn()
|
||||
}
|
||||
|
||||
func (m *Backend) Connections() uint {
|
||||
if m.ConnectionsFn == nil {
|
||||
return 2
|
||||
func (m *Backend) Properties() backend.Properties {
|
||||
if m.PropertiesFn == nil {
|
||||
return backend.Properties{
|
||||
Connections: 2,
|
||||
HasAtomicReplace: false,
|
||||
}
|
||||
}
|
||||
|
||||
return m.ConnectionsFn()
|
||||
return m.PropertiesFn()
|
||||
}
|
||||
|
||||
// Hasher may return a hash function for calculating a content hash for the backend
|
||||
@@ -59,14 +61,6 @@ func (m *Backend) Hasher() hash.Hash {
|
||||
return m.HasherFn()
|
||||
}
|
||||
|
||||
// HasAtomicReplace returns whether Save() can atomically replace files
|
||||
func (m *Backend) HasAtomicReplace() bool {
|
||||
if m.HasAtomicReplaceFn == nil {
|
||||
return false
|
||||
}
|
||||
return m.HasAtomicReplaceFn()
|
||||
}
|
||||
|
||||
// IsNotExist returns true if the error is caused by a missing file.
|
||||
func (m *Backend) IsNotExist(err error) bool {
|
||||
if m.IsNotExistFn == nil {
|
||||
|
||||
Reference in New Issue
Block a user