MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / persist

Method persist

internal/desktop/tool_cache.go:101–122  ·  view source on GitHub ↗

persist writes the in-memory entries to disk atomically. Best-effort: a write failure only means the next cold start re-probes, which is correct.

()

Source from the content-addressed store, hash-verified

99// persist writes the in-memory entries to disk atomically. Best-effort: a
100// write failure only means the next cold start re-probes, which is correct.
101func (c *detectionCache) persist() {
102 c.mu.RLock()
103 file := detectionCacheFile{Tools: make(map[string]detectionEntry, len(c.entries))}
104 for name, entry := range c.entries {
105 file.Tools[name] = entry
106 }
107 path := c.path
108 c.mu.RUnlock()
109
110 if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
111 return
112 }
113 payload, err := json.MarshalIndent(file, "", " ")
114 if err != nil {
115 return
116 }
117 tmp := fmt.Sprintf("%s.tmp.%d", path, os.Getpid())
118 if err := os.WriteFile(tmp, payload, 0o600); err != nil {
119 return
120 }
121 _ = os.Rename(tmp, path)
122}

Callers 3

ListMethod · 0.80

Calls 1

RenameMethod · 0.45