2023-04-07 20:01:30 +00:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
"github.com/restic/restic/internal/backend"
|
2023-04-07 20:01:30 +00:00
|
|
|
"github.com/restic/restic/internal/debug"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Backend struct {
|
2023-10-01 09:40:12 +00:00
|
|
|
backend.Backend
|
2023-04-07 20:01:30 +00:00
|
|
|
}
|
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
// statically ensure that Backend implements backend.Backend.
|
|
|
|
var _ backend.Backend = &Backend{}
|
2023-04-07 20:01:30 +00:00
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
func New(be backend.Backend) *Backend {
|
2023-04-07 20:01:30 +00:00
|
|
|
return &Backend{Backend: be}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (be *Backend) IsNotExist(err error) bool {
|
|
|
|
isNotExist := be.Backend.IsNotExist(err)
|
|
|
|
debug.Log("IsNotExist(%T, %#v, %v)", err, err, isNotExist)
|
|
|
|
return isNotExist
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save adds new Data to the backend.
|
2023-10-01 09:40:12 +00:00
|
|
|
func (be *Backend) Save(ctx context.Context, h backend.Handle, rd backend.RewindReader) error {
|
2023-04-07 20:01:30 +00:00
|
|
|
debug.Log("Save(%v, %v)", h, rd.Length())
|
|
|
|
err := be.Backend.Save(ctx, h, rd)
|
|
|
|
debug.Log(" save err %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove deletes a file from the backend.
|
2023-10-01 09:40:12 +00:00
|
|
|
func (be *Backend) Remove(ctx context.Context, h backend.Handle) error {
|
2023-04-07 20:01:30 +00:00
|
|
|
debug.Log("Remove(%v)", h)
|
|
|
|
err := be.Backend.Remove(ctx, h)
|
|
|
|
debug.Log(" remove err %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
func (be *Backend) Load(ctx context.Context, h backend.Handle, length int, offset int64, fn func(io.Reader) error) error {
|
2023-04-07 20:01:30 +00:00
|
|
|
debug.Log("Load(%v, length %v, offset %v)", h, length, offset)
|
|
|
|
err := be.Backend.Load(ctx, h, length, offset, fn)
|
|
|
|
debug.Log(" load err %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
func (be *Backend) Stat(ctx context.Context, h backend.Handle) (backend.FileInfo, error) {
|
2023-04-07 20:01:30 +00:00
|
|
|
debug.Log("Stat(%v)", h)
|
|
|
|
fi, err := be.Backend.Stat(ctx, h)
|
|
|
|
debug.Log(" stat err %v", err)
|
|
|
|
return fi, err
|
|
|
|
}
|
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
func (be *Backend) List(ctx context.Context, t backend.FileType, fn func(backend.FileInfo) error) error {
|
2023-04-07 20:01:30 +00:00
|
|
|
debug.Log("List(%v)", t)
|
|
|
|
err := be.Backend.List(ctx, t, fn)
|
|
|
|
debug.Log(" list err %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (be *Backend) Delete(ctx context.Context) error {
|
|
|
|
debug.Log("Delete()")
|
|
|
|
err := be.Backend.Delete(ctx)
|
|
|
|
debug.Log(" delete err %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (be *Backend) Close() error {
|
|
|
|
debug.Log("Close()")
|
|
|
|
err := be.Backend.Close()
|
|
|
|
debug.Log(" close err %v", err)
|
|
|
|
return err
|
|
|
|
}
|
2023-04-08 10:53:43 +00:00
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
func (be *Backend) Unwrap() backend.Backend { return be.Backend }
|