Skip to content

Commit 305d1f5

Browse files
committed
repo: return bytes and CID from GetRecordBytes
1 parent 5fa47cd commit 305d1f5

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

atproto/repo/repo.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ func (repo *Repo) GetRecordCID(ctx context.Context, collection syntax.NSID, rkey
4848
return c, nil
4949
}
5050

51-
func (repo *Repo) GetRecordBytes(ctx context.Context, collection syntax.NSID, rkey syntax.RecordKey) ([]byte, error) {
51+
func (repo *Repo) GetRecordBytes(ctx context.Context, collection syntax.NSID, rkey syntax.RecordKey) ([]byte, *cid.Cid, error) {
5252
c, err := repo.GetRecordCID(ctx, collection, rkey)
5353
if err != nil {
54-
return nil, err
54+
return nil, nil, err
5555
}
5656
blk, err := repo.RecordStore.Get(ctx, *c)
5757
if err != nil {
58-
return nil, err
58+
return nil, nil, err
5959
}
6060
// TODO: not verifying CID
61-
return blk.RawData(), nil
61+
return blk.RawData(), c, nil
6262
}
6363

6464
// Snapshots the current state of the repository, resulting in a new (unsigned) `Commit` struct.

atproto/repo/sync.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,14 @@ func VerifyCommitMessage(ctx context.Context, msg *comatproto.SyncSubscribeRepos
6161
if err != nil {
6262
return nil, fmt.Errorf("invalid repo path in ops list: %w", err)
6363
}
64-
val, err := repo.GetRecordCID(ctx, nsid, rkey)
64+
// don't use the returned bytes, but do actually read them out of store (not just CID)
65+
_, val, err := repo.GetRecordBytes(ctx, nsid, rkey)
6566
if err != nil {
6667
return nil, err
6768
}
6869
if *c != *val {
6970
return nil, fmt.Errorf("record op doesn't match MST tree value")
7071
}
71-
_, err = repo.GetRecordBytes(ctx, nsid, rkey)
72-
if err != nil {
73-
return nil, err
74-
}
7572
}
7673
}
7774

0 commit comments

Comments
 (0)