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

Function LoadState

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

LoadState reads the state file for a source. Returns empty state if file doesn't exist.

(dir, sourceName string)

Source from the content-addressed store, hash-verified

30
31// LoadState reads the state file for a source. Returns empty state if file doesn't exist.
32func LoadState(dir, sourceName string) (*SyncState, error) {
33 path := stateFilePath(dir, sourceName)
34 data, err := os.ReadFile(path)
35 if os.IsNotExist(err) {
36 return &SyncState{
37 Source: sourceName,
38 Tasks: make(map[string]TaskState),
39 }, nil
40 }
41 if err != nil {
42 return nil, fmt.Errorf("failed to read state file: %w", err)
43 }
44
45 var state SyncState
46 if err := yaml.Unmarshal(data, &state); err != nil {
47 return nil, fmt.Errorf("failed to parse state file: %w", err)
48 }
49
50 if state.Tasks == nil {
51 state.Tasks = make(map[string]TaskState)
52 }
53
54 return &state, nil
55}
56
57// SaveState writes the state file for a source.
58func SaveState(dir, sourceName string, state *SyncState) error {

Callers 7

RunSyncMethod · 0.85
TestEngine_DryRunFunction · 0.85

Calls 1

stateFilePathFunction · 0.85

Tested by 6

TestEngine_DryRunFunction · 0.68