返回 DeepSeek-Reasonix
store_archive_id.go
根目录 / internal / memory / store_archive_id.go
1 package memory
2
3 import "path/filepath"
4
5 // archiveByID archives every active copy of a fact that shares the given ID
6 // across directories (migration duplicates share the deterministic ID), while
7 // same-named facts with a different ID stay put. Returns the last path
8 // archived. The unqualified-name path already archives from every directory.
9 func (s Store) archiveByID(name, id string) (string, error) {
10 var lastPath string
11 for _, dir := range s.dirs() {
12 if dir == "" || !memoryIDInDir(dir, name, id) {
13 continue
14 }
15 p, err := archiveMemoryInDir(dir, name)
16 if err != nil {
17 return "", err
18 }
19 if p != "" {
20 lastPath = p
21 }
22 }
23 return lastPath, nil
24 }
25
26 // memoryIDInDir reports whether dir holds an active fact with the given ID.
27 // Used to archive every migration duplicate of an ID while leaving same-named
28 // facts with a different identity untouched.
29 func memoryIDInDir(dir, name, id string) bool {
30 m, ok := loadMemory(filepath.Join(dir, name+".md"))
31 return ok && m.ID == id
32 }
33
33 lines GO