From ca6b7ec5330b33450c56dbe58be0032fa7cd4132 Mon Sep 17 00:00:00 2001 From: Matthieu Rakotojaona Date: Sun, 19 Jul 2015 15:16:16 +0200 Subject: [PATCH] Add Index.LookupSize --- cmd/restic/fuse/file.go | 5 ++--- repository/index.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/restic/fuse/file.go b/cmd/restic/fuse/file.go index ff28ebf85..b207d939c 100644 --- a/cmd/restic/fuse/file.go +++ b/cmd/restic/fuse/file.go @@ -2,7 +2,6 @@ package fuse import ( "github.com/restic/restic" - "github.com/restic/restic/crypto" "github.com/restic/restic/pack" "github.com/restic/restic/repository" @@ -25,11 +24,11 @@ type file struct { func newFile(repo *repository.Repository, node *restic.Node) (*file, error) { sizes := make([]uint32, len(node.Content)) for i, blobId := range node.Content { - _, _, _, length, err := repo.Index().Lookup(blobId) + length, err := repo.Index().LookupSize(blobId) if err != nil { return nil, err } - sizes[i] = uint32(length) - crypto.Extension + sizes[i] = uint32(length) } return &file{ diff --git a/repository/index.go b/repository/index.go index d7bd4bf16..2fcc67cbc 100644 --- a/repository/index.go +++ b/repository/index.go @@ -7,6 +7,7 @@ import ( "sync" "github.com/restic/restic/backend" + "github.com/restic/restic/crypto" "github.com/restic/restic/debug" "github.com/restic/restic/pack" ) @@ -91,6 +92,16 @@ func (idx *Index) Has(id backend.ID) bool { return false } +// LookupSize returns the length of the cleartext content behind the +// given id +func (idx *Index) LookupSize(id backend.ID) (cleartextLength uint, err error) { + _, _, _, encryptedLength, err := idx.Lookup(id) + if err != nil { + return 0, err + } + return encryptedLength - crypto.Extension, nil +} + // Merge loads all items from other into idx. func (idx *Index) Merge(other *Index) { debug.Log("Index.Merge", "Merge index with %p", other)