cleanup indirect object creation logic, which has historically been quite messy, with the new code structure it's much more readable
@@ -55,7 +55,6 @@ type objectWriter struct {
blockIndex []indirectObjectEntry
description string
- indirectLevel int32
blockTracker *blockTracker
splitter objectSplitter
@@ -144,16 +143,11 @@ 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,
@@ -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 {
