返回 DeepSeek-Reasonix
content_snapshot.go
根目录 / internal / sessioninbox / content_snapshot.go
1 package sessioninbox
2
3 import (
4 "encoding/json"
5 "os"
6 "path/filepath"
7
8 "reasonix/internal/attachment"
9 "reasonix/internal/sessioncontent"
10 )
11
12 // FrozenContentRefs reads only manifest-reachable blobs. The caller owns the
13 // disk transaction lock or an exclusive copied snapshot; no state is created.
14 func FrozenContentRefs(dir string) ([]sessioncontent.Ref, error) {
15 data, err := readRegularFile(filepath.Join(dir, manifestName), maxManifestBytes)
16 if os.IsNotExist(err) {
17 return nil, nil
18 }
19 if err != nil {
20 return nil, err
21 }
22 man, err := decodeManifest(data)
23 if err != nil {
24 return nil, err
25 }
26 if man.SchemaVersion > SchemaVersion {
27 return nil, ErrSchemaReadonly
28 }
29 reader := &Store{dir: dir, limits: (Limits{}).withDefaults()}
30 var refs []sessioncontent.Ref
31 for _, item := range man.Items {
32 env, err := reader.readBlobLocked(blobNameFor(item), item.Checksum)
33 if err != nil {
34 return nil, err
35 }
36 body, err := json.Marshal(env)
37 if err != nil {
38 return nil, err
39 }
40 refs = append(refs, attachment.CollectJSONRefs(body)...)
41 }
42 return refs, nil
43 }
44
44 lines GO