MCPcopy Create free account
hub / github.com/B33pBeeps/redthread / SaveWorkspace

Function SaveWorkspace

internal/app/storage.go:132–156  ·  view source on GitHub ↗

SaveWorkspace writes the workspace as a v4 file (workspace envelope).

(w *Workspace)

Source from the content-addressed store, hash-verified

130
131// SaveWorkspace writes the workspace as a v4 file (workspace envelope).
132func SaveWorkspace(w *Workspace) error {
133 path, err := DataPath()
134 if err != nil {
135 return err
136 }
137 f := diskFile{
138 SchemaVersion: schemaVersion,
139 ActiveIdx: w.ActiveIdx,
140 Boards: w.Boards,
141 }
142 // Always persist the background — cork=false is meaningful, and the
143 // legacy Mode field must never be written.
144 bg := w.Background
145 bg.Mode = ""
146 f.Background = &bg
147 data, err := json.MarshalIndent(f, "", " ")
148 if err != nil {
149 return err
150 }
151 tmp := path + ".tmp"
152 if err := os.WriteFile(tmp, data, 0o644); err != nil {
153 return err
154 }
155 return os.Rename(tmp, path)
156}
157
158// --- debouncer --------------------------------------------------------
159

Callers 4

TouchMethod · 0.85
FlushMethod · 0.85
RunFunction · 0.85

Calls 1

DataPathFunction · 0.85

Tested by 1