Fix building list

This commit is contained in:
mcrakhman 2022-10-28 13:24:05 +02:00
parent 5904815908
commit 8f862fd1a1
No known key found for this signature in database
GPG Key ID: DED12CFEF5B8396B

View File

@ -64,16 +64,6 @@ func BuildACLList(storage storage.ListStorage) (ACLList, error) {
} }
func build(id string, stateBuilder *aclStateBuilder, recBuilder ACLRecordBuilder, storage storage.ListStorage) (list ACLList, err error) { func build(id string, stateBuilder *aclStateBuilder, recBuilder ACLRecordBuilder, storage storage.ListStorage) (list ACLList, err error) {
// TODO: need to add context here
rootWithId, err := storage.Root()
if err != nil {
return
}
aclRecRoot, err := recBuilder.ConvertFromRaw(rootWithId)
if err != nil {
return
}
head, err := storage.Head() head, err := storage.Head()
if err != nil { if err != nil {
return return
@ -90,7 +80,7 @@ func build(id string, stateBuilder *aclStateBuilder, recBuilder ACLRecordBuilder
} }
records := []*ACLRecord{record} records := []*ACLRecord{record}
for record.PrevId != "" && record.PrevId != id { for record.PrevId != "" {
rawRecordWithId, err = storage.GetRawRecord(context.Background(), record.PrevId) rawRecordWithId, err = storage.GetRawRecord(context.Background(), record.PrevId)
if err != nil { if err != nil {
return return
@ -102,8 +92,6 @@ func build(id string, stateBuilder *aclStateBuilder, recBuilder ACLRecordBuilder
} }
records = append(records, record) records = append(records, record)
} }
// adding root in the end, because we already parsed it
records = append(records, aclRecRoot)
indexes := make(map[string]int) indexes := make(map[string]int)
for i, j := 0, len(records)-1; i < j; i, j = i+1, j-1 { for i, j := 0, len(records)-1; i < j; i, j = i+1, j-1 {
@ -122,6 +110,15 @@ func build(id string, stateBuilder *aclStateBuilder, recBuilder ACLRecordBuilder
return return
} }
rootWithId, err := storage.Root()
if err != nil {
return
}
aclRecRoot, err := recBuilder.ConvertFromRaw(rootWithId)
if err != nil {
return
}
list = &aclList{ list = &aclList{
root: aclRecRoot.Model.(*aclrecordproto.ACLRoot), root: aclRecRoot.Model.(*aclrecordproto.ACLRoot),
records: records, records: records,