1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-11 02:13:49 +09:00

Fix change builder with no root

This commit is contained in:
mcrakhman 2023-03-02 21:08:14 +01:00
parent 6e5d044251
commit 5218eea8ad
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B

View file

@ -220,7 +220,7 @@ func (c *changeBuilder) Build(payload BuilderContent) (ch *Change, rawIdChange *
}
func (c *changeBuilder) Marshall(ch *Change) (raw *treechangeproto.RawTreeChangeWithId, err error) {
if ch.Id == c.rootChange.Id {
if c.isRoot(ch.Id) {
return c.rootChange, nil
}
treeChange := &treechangeproto.TreeChange{
@ -255,7 +255,7 @@ func (c *changeBuilder) Marshall(ch *Change) (raw *treechangeproto.RawTreeChange
}
func (c *changeBuilder) unmarshallRawChange(raw *treechangeproto.RawTreeChange, id string) (ch *Change, err error) {
if c.rootChange.Id == id {
if c.isRoot(id) {
unmarshalled := &treechangeproto.RootChange{}
err = proto.Unmarshal(raw.Payload, unmarshalled)
if err != nil {
@ -274,3 +274,10 @@ func (c *changeBuilder) unmarshallRawChange(raw *treechangeproto.RawTreeChange,
ch = NewChange(id, unmarshalled, raw.Signature)
return
}
func (c *changeBuilder) isRoot(id string) bool {
if c.rootChange != nil {
return c.rootChange.Id == id
}
return false
}