From 4b2a4b03ece8f6e87ca86eaf9f4b2a919c1a9bd4 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 12 Oct 2015 22:49:31 +0200 Subject: [PATCH] Remove Index.StoreInProgress() --- repository/index.go | 24 --------------- repository/index_test.go | 66 ---------------------------------------- 2 files changed, 90 deletions(-) diff --git a/repository/index.go b/repository/index.go index 11a84e29b..9a0891f1f 100644 --- a/repository/index.go +++ b/repository/index.go @@ -70,30 +70,6 @@ func (idx *Index) Store(t pack.BlobType, id backend.ID, pack *backend.ID, offset idx.store(t, id, pack, offset, length) } -// StoreInProgress adds a preliminary index entry for a blob that is about to be -// saved. The entry must be updated using Store once the the blob has been -// written to a pack. Adding an preliminary index fails if there's an existing -// entry associated with the same id. -func (idx *Index) StoreInProgress(t pack.BlobType, id backend.ID) error { - idx.m.Lock() - defer idx.m.Unlock() - - if idx.final { - panic("store new item in finalized index") - } - - if _, hasID := idx.pack[id]; hasID { - errorMsg := fmt.Sprintf("index already contains id %v (%v)", id.Str(), t) - debug.Log("Index.StoreInProgress", errorMsg) - return errors.New(errorMsg) - } - - idx.store(t, id, nil, 0, 0) - debug.Log("Index.StoreInProgress", "preliminary entry added for id %v (%v)", - id.Str(), t) - return nil -} - // Remove removes the pack ID from the index. func (idx *Index) Remove(packID backend.ID) { idx.m.Lock() diff --git a/repository/index_test.go b/repository/index_test.go index 3398c90d3..4b713eaa7 100644 --- a/repository/index_test.go +++ b/repository/index_test.go @@ -325,69 +325,3 @@ func TestConvertIndex(t *testing.T) { } }) } - -func TestStoreOverwritesPreliminaryEntry(t *testing.T) { - idx := repository.NewIndex() - - blobID := randomID() - dataType := pack.Data - err := idx.StoreInProgress(dataType, blobID) - OK(t, err) - - packID := randomID() - offset := uint(0) - length := uint(100) - idx.Store(dataType, blobID, &packID, offset, length) - - actPackID, actType, actOffset, actLength, err := idx.Lookup(blobID) - OK(t, err) - Equals(t, packID, *actPackID) - Equals(t, dataType, actType) - Equals(t, offset, actOffset) - Equals(t, length, actLength) -} - -func TestStoreInProgressAddsPreliminaryEntry(t *testing.T) { - idx := repository.NewIndex() - - blobID := randomID() - dataType := pack.Data - - err := idx.StoreInProgress(dataType, blobID) - OK(t, err) - - actPackID, actType, actOffset, actLength, err := idx.Lookup(blobID) - OK(t, err) - Assert(t, actPackID == nil, - "Preliminary index entry illegaly associated with a pack id.") - Equals(t, uint(0), actOffset) - Equals(t, uint(0), actLength) - Equals(t, dataType, actType) -} - -func TestStoreInProgressRefusesToOverwriteExistingFinalEntry(t *testing.T) { - idx := repository.NewIndex() - - blobID := randomID() - dataType := pack.Data - packID := randomID() - offset := uint(0) - length := uint(100) - idx.Store(dataType, blobID, &packID, offset, length) - - err := idx.StoreInProgress(dataType, blobID) - Assert(t, err != nil, - "index.StoreInProgress did not refuse to overwrite existing entry") -} - -func TestStoreInProgressRefusesToOverwriteExistingPreliminaryEntry(t *testing.T) { - idx := repository.NewIndex() - - blobID := randomID() - dataType := pack.Data - - _ = idx.StoreInProgress(dataType, blobID) - err := idx.StoreInProgress(dataType, blobID) - Assert(t, err != nil, - "index.StoreInProgress did not refuse to overwrite existing entry") -}