-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
54 lines (47 loc) · 1.06 KB
/
state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"encoding/json"
"os"
)
type projectType int
const (
ptUndef projectType = iota
ptMovie
ptShow
)
func (pt projectType) String() string {
switch pt {
case ptUndef: return "ptUndef"
case ptMovie: return "ptMovie"
case ptShow: return "ptShow"
}
panic("unexpected projectType value")
}
type toolState struct {
Pt projectType
Name string
// Set if TMM has forced an override to the otherwise-computed project name.
TmmDirOverride string
}
func readToolState(path string) (ts *toolState, err error) {
bytes, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
// Special case: state file doesn't exist.
ts = &toolState{}
err = nil
return
}
return
}
ts = &toolState{}
err = json.Unmarshal(bytes, ts)
return
}
func writeToolState(ts *toolState, path string) error {
bytes, err := json.Marshal(ts)
if err != nil {
return err
}
return os.WriteFile(path, bytes, 0644)
}