From 461d54e43cc2aef3b7ea21e44b2c0a7aa3d20650 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 25 Oct 2015 17:05:54 +0100 Subject: [PATCH] Refactor repository.SaveIndex() --- repository/repository.go | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/repository/repository.go b/repository/repository.go index 5f1650c62..e841c692d 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -507,28 +507,37 @@ func (bw *BlobWriter) ID() backend.ID { return bw.id } +// SaveIndex saves an index to repo's backend. +func SaveIndex(repo *Repository, index *Index) (backend.ID, error) { + blob, err := repo.CreateEncryptedBlob(backend.Index) + if err != nil { + return backend.ID{}, err + } + + err = index.Finalize(blob) + if err != nil { + return backend.ID{}, err + } + + err = blob.Close() + if err != nil { + return backend.ID{}, err + } + + sid := blob.ID() + return sid, nil +} + // saveIndex saves all indexes in the backend. func (r *Repository) saveIndex(indexes ...*Index) error { for i, idx := range indexes { debug.Log("Repo.SaveIndex", "Saving index %d", i) - blob, err := r.CreateEncryptedBlob(backend.Index) + sid, err := SaveIndex(r, idx) if err != nil { return err } - err = idx.Finalize(blob) - if err != nil { - return err - } - - err = blob.Close() - if err != nil { - return err - } - - sid := blob.ID() - debug.Log("Repo.SaveIndex", "Saved index %d as %v", i, sid.Str()) }