forked from TrueCloudLab/restic
repository: remove Packer and SavePacker from public interface
This commit is contained in:
parent
550d1eeac3
commit
04ad9f0c0c
3 changed files with 18 additions and 18 deletions
|
@ -21,8 +21,8 @@ import (
|
|||
"github.com/minio/sha256-simd"
|
||||
)
|
||||
|
||||
// Packer holds a pack.Packer together with a hash writer.
|
||||
type Packer struct {
|
||||
// packer holds a pack.packer together with a hash writer.
|
||||
type packer struct {
|
||||
*pack.Packer
|
||||
tmpfile *os.File
|
||||
bufWr *bufio.Writer
|
||||
|
@ -32,16 +32,16 @@ type Packer struct {
|
|||
type packerManager struct {
|
||||
tpe restic.BlobType
|
||||
key *crypto.Key
|
||||
queueFn func(ctx context.Context, t restic.BlobType, p *Packer) error
|
||||
queueFn func(ctx context.Context, t restic.BlobType, p *packer) error
|
||||
|
||||
pm sync.Mutex
|
||||
packer *Packer
|
||||
packer *packer
|
||||
packSize uint
|
||||
}
|
||||
|
||||
// newPackerManager returns a new packer manager which writes temporary files
|
||||
// to a temporary directory
|
||||
func newPackerManager(key *crypto.Key, tpe restic.BlobType, packSize uint, queueFn func(ctx context.Context, t restic.BlobType, p *Packer) error) *packerManager {
|
||||
func newPackerManager(key *crypto.Key, tpe restic.BlobType, packSize uint, queueFn func(ctx context.Context, t restic.BlobType, p *packer) error) *packerManager {
|
||||
return &packerManager{
|
||||
tpe: tpe,
|
||||
key: key,
|
||||
|
@ -114,7 +114,7 @@ func (r *packerManager) SaveBlob(ctx context.Context, t restic.BlobType, id rest
|
|||
|
||||
// findPacker returns a packer for a new blob of size bytes. Either a new one is
|
||||
// created or one is returned that already has some blobs.
|
||||
func (r *packerManager) newPacker() (packer *Packer, err error) {
|
||||
func (r *packerManager) newPacker() (pck *packer, err error) {
|
||||
debug.Log("create new pack")
|
||||
tmpfile, err := fs.TempFile("", "restic-temp-pack-")
|
||||
if err != nil {
|
||||
|
@ -123,17 +123,17 @@ func (r *packerManager) newPacker() (packer *Packer, err error) {
|
|||
|
||||
bufWr := bufio.NewWriter(tmpfile)
|
||||
p := pack.NewPacker(r.key, bufWr)
|
||||
packer = &Packer{
|
||||
pck = &packer{
|
||||
Packer: p,
|
||||
tmpfile: tmpfile,
|
||||
bufWr: bufWr,
|
||||
}
|
||||
|
||||
return packer, nil
|
||||
return pck, nil
|
||||
}
|
||||
|
||||
// savePacker stores p in the backend.
|
||||
func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *Packer) error {
|
||||
func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *packer) error {
|
||||
debug.Log("save packer for %v with %d blobs (%d bytes)\n", t, p.Packer.Count(), p.Packer.Size())
|
||||
err := p.Packer.Finalize()
|
||||
if err != nil {
|
||||
|
|
|
@ -70,7 +70,7 @@ func testPackerManager(t testing.TB) int64 {
|
|||
rnd := rand.New(rand.NewSource(randomSeed))
|
||||
|
||||
savedBytes := int(0)
|
||||
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, DefaultPackSize, func(ctx context.Context, tp restic.BlobType, p *Packer) error {
|
||||
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, DefaultPackSize, func(ctx context.Context, tp restic.BlobType, p *packer) error {
|
||||
err := p.Finalize()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -92,7 +92,7 @@ func testPackerManager(t testing.TB) int64 {
|
|||
func TestPackerManagerWithOversizeBlob(t *testing.T) {
|
||||
packFiles := int(0)
|
||||
sizeLimit := uint(512 * 1024)
|
||||
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, sizeLimit, func(ctx context.Context, tp restic.BlobType, p *Packer) error {
|
||||
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, sizeLimit, func(ctx context.Context, tp restic.BlobType, p *packer) error {
|
||||
packFiles++
|
||||
return nil
|
||||
})
|
||||
|
@ -122,7 +122,7 @@ func BenchmarkPackerManager(t *testing.B) {
|
|||
|
||||
for i := 0; i < t.N; i++ {
|
||||
rnd.Seed(randomSeed)
|
||||
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, DefaultPackSize, func(ctx context.Context, t restic.BlobType, p *Packer) error {
|
||||
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, DefaultPackSize, func(ctx context.Context, t restic.BlobType, p *packer) error {
|
||||
return nil
|
||||
})
|
||||
fillPacks(t, rnd, pm, blobBuf)
|
||||
|
|
|
@ -7,13 +7,13 @@ import (
|
|||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
// SavePacker implements saving a pack in the repository.
|
||||
type SavePacker interface {
|
||||
savePacker(ctx context.Context, t restic.BlobType, p *Packer) error
|
||||
// savePacker implements saving a pack in the repository.
|
||||
type savePacker interface {
|
||||
savePacker(ctx context.Context, t restic.BlobType, p *packer) error
|
||||
}
|
||||
|
||||
type uploadTask struct {
|
||||
packer *Packer
|
||||
packer *packer
|
||||
tpe restic.BlobType
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ type packerUploader struct {
|
|||
uploadQueue chan uploadTask
|
||||
}
|
||||
|
||||
func newPackerUploader(ctx context.Context, wg *errgroup.Group, repo SavePacker, connections uint) *packerUploader {
|
||||
func newPackerUploader(ctx context.Context, wg *errgroup.Group, repo savePacker, connections uint) *packerUploader {
|
||||
pu := &packerUploader{
|
||||
uploadQueue: make(chan uploadTask),
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func newPackerUploader(ctx context.Context, wg *errgroup.Group, repo SavePacker,
|
|||
return pu
|
||||
}
|
||||
|
||||
func (pu *packerUploader) QueuePacker(ctx context.Context, t restic.BlobType, p *Packer) (err error) {
|
||||
func (pu *packerUploader) QueuePacker(ctx context.Context, t restic.BlobType, p *packer) (err error) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
|
|
Loading…
Reference in a new issue