MCPcopy Create free account
hub / github.com/driangle/taskmd / SaveState

Function SaveState

apps/cli/internal/sync/state.go:58–75  ·  view source on GitHub ↗

SaveState writes the state file for a source.

(dir, sourceName string, state *SyncState)

Source from the content-addressed store, hash-verified

56
57// SaveState writes the state file for a source.
58func SaveState(dir, sourceName string, state *SyncState) error {
59 stateDir := filepath.Join(dir, stateSubDir)
60 if err := os.MkdirAll(stateDir, 0755); err != nil {
61 return fmt.Errorf("failed to create state directory: %w", err)
62 }
63
64 data, err := yaml.Marshal(state)
65 if err != nil {
66 return fmt.Errorf("failed to marshal state: %w", err)
67 }
68
69 path := stateFilePath(dir, sourceName)
70 if err := os.WriteFile(path, data, 0644); err != nil {
71 return fmt.Errorf("failed to write state file: %w", err)
72 }
73
74 return nil
75}
76
77func stateFilePath(dir, sourceName string) string {
78 return filepath.Join(dir, stateSubDir, sourceName+".yaml")

Callers 3

RunSyncMethod · 0.85

Calls 1

stateFilePathFunction · 0.85

Tested by 2