From 60a34087c914f38899b1df7c99f02ed217c40b4d Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 2 Nov 2015 18:51:24 +0100 Subject: [PATCH] Move LoadIndexWithDecoder to index.go --- repository/index.go | 26 ++++++++++++++++++++++++++ repository/repository.go | 19 ------------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/repository/index.go b/repository/index.go index 1f9d65ad1..d74131b84 100644 --- a/repository/index.go +++ b/repository/index.go @@ -514,6 +514,32 @@ func ConvertIndexes(repo *Repository) error { return nil } +// LoadIndexWithDecoder loads the index and decodes it with fn. +func LoadIndexWithDecoder(repo *Repository, id string, fn func(io.Reader) (*Index, error)) (*Index, error) { + debug.Log("LoadIndexWithDecoder", "Loading index %v", id[:8]) + + idxID, err := backend.ParseID(id) + if err != nil { + return nil, err + } + + rd, err := repo.GetDecryptReader(backend.Index, idxID.String()) + if err != nil { + return nil, err + } + defer rd.Close() + + idx, err := fn(rd) + if err != nil { + debug.Log("LoadIndexWithDecoder", "error while decoding index %v: %v", id, err) + return nil, err + } + + idx.id = idxID + + return idx, nil +} + // ConvertIndex loads the given index from the repo and converts them to the new // format (if necessary). When the conversion is succcessful, the old index // is removed. Returned is either the old id (if no conversion was needed) or diff --git a/repository/repository.go b/repository/repository.go index 51e5613b4..d119d51d5 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -650,25 +650,6 @@ func (r *Repository) GetDecryptReader(t backend.Type, id string) (io.ReadCloser, return newDecryptReadCloser(r.key, rd) } -// LoadIndexWithDecoder loads the index and decodes it with fn. -func LoadIndexWithDecoder(repo *Repository, id string, fn func(io.Reader) (*Index, error)) (*Index, error) { - debug.Log("LoadIndexWithDecoder", "Loading index %v", id[:8]) - - rd, err := repo.GetDecryptReader(backend.Index, id) - if err != nil { - return nil, err - } - defer rd.Close() - - idx, err := fn(rd) - if err != nil { - debug.Log("LoadIndexWithDecoder", "error while decoding index %v: %v", id, err) - return nil, err - } - - return idx, nil -} - // SearchKey finds a key with the supplied password, afterwards the config is // read and parsed. func (r *Repository) SearchKey(password string) error {