mirror of https://github.com/restic/restic.git
Replace duplicate type checking in cache with a function
This commit is contained in:
parent
1b1a2115fa
commit
f9b6f8fd45
|
@ -43,14 +43,13 @@ func (b *Backend) Remove(ctx context.Context, h restic.Handle) error {
|
||||||
return b.Cache.remove(h)
|
return b.Cache.remove(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
var autoCacheTypes = map[restic.FileType]struct{}{
|
func autoCached(t restic.FileType) bool {
|
||||||
restic.IndexFile: {},
|
return t == restic.IndexFile || t == restic.SnapshotFile
|
||||||
restic.SnapshotFile: {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save stores a new file in the backend and the cache.
|
// Save stores a new file in the backend and the cache.
|
||||||
func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error {
|
func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error {
|
||||||
if _, ok := autoCacheTypes[h.Type]; !ok {
|
if !autoCached(h.Type) {
|
||||||
return b.Backend.Save(ctx, h, rd)
|
return b.Backend.Save(ctx, h, rd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,11 +83,6 @@ func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRea
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var autoCacheFiles = map[restic.FileType]bool{
|
|
||||||
restic.IndexFile: true,
|
|
||||||
restic.SnapshotFile: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Backend) cacheFile(ctx context.Context, h restic.Handle) error {
|
func (b *Backend) cacheFile(ctx context.Context, h restic.Handle) error {
|
||||||
finish := make(chan struct{})
|
finish := make(chan struct{})
|
||||||
|
|
||||||
|
@ -192,7 +186,7 @@ func (b *Backend) Load(ctx context.Context, h restic.Handle, length int, offset
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we don't automatically cache this file type, fall back to the backend
|
// if we don't automatically cache this file type, fall back to the backend
|
||||||
if _, ok := autoCacheFiles[h.Type]; !ok {
|
if !autoCached(h.Type) {
|
||||||
debug.Log("Load(%v, %v, %v): delegating to backend", h, length, offset)
|
debug.Log("Load(%v, %v, %v): delegating to backend", h, length, offset)
|
||||||
return b.Backend.Load(ctx, h, length, offset, consumer)
|
return b.Backend.Load(ctx, h, length, offset, consumer)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue