From fa7c558aaf1ad73f1e52f4d1e161ad2ec3293f2e Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Sat, 19 Aug 2017 14:29:39 -0700 Subject: [PATCH] cleanup indirect object creation logic, which has historically been quite messy, with the new code structure it's much more readable --- repo/object_writer.go | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/repo/object_writer.go b/repo/object_writer.go index 378dd8703..708a3b830 100644 --- a/repo/object_writer.go +++ b/repo/object_writer.go @@ -54,8 +54,7 @@ type objectWriter struct { currentPosition int64 blockIndex []indirectObjectEntry - description string - indirectLevel int32 + description string blockTracker *blockTracker splitter objectSplitter @@ -144,20 +143,15 @@ func (w *objectWriter) Result() (ObjectID, error) { } if len(w.blockIndex) == 1 { - return addIndirection(w.blockIndex[0].Object, w.indirectLevel), nil - } - - if len(w.blockIndex) == 0 { - return NullObjectID, nil + return w.blockIndex[0].Object, nil } iw := &objectWriter{ - repo: w.repo, - indirectLevel: w.indirectLevel + 1, - prefix: w.prefix, - description: "LIST(" + w.description + ")", - blockTracker: w.blockTracker, - splitter: w.repo.newSplitter(), + repo: w.repo, + prefix: w.prefix, + description: "LIST(" + w.description + ")", + blockTracker: w.blockTracker, + splitter: w.repo.newSplitter(), disablePacking: w.disablePacking, packGroup: w.packGroup, @@ -168,15 +162,11 @@ func (w *objectWriter) Result() (ObjectID, error) { jw.Write(&e) } jw.Finalize() - return iw.Result() -} - -func addIndirection(oid ObjectID, level int32) ObjectID { - if level == 0 { - return oid + oid, err := iw.Result() + if err != nil { + return NullObjectID, err } - - return addIndirection(ObjectID{Indirect: &oid}, level-1) + return ObjectID{Indirect: &oid}, nil } func (w *objectWriter) StorageBlocks() []string {