-
Notifications
You must be signed in to change notification settings - Fork 34
/
action_sync.go
57 lines (48 loc) · 1.13 KB
/
action_sync.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
55
56
57
package teacluster
import (
"github.com/TeaWeb/code/teacluster/configs"
"github.com/TeaWeb/code/teahooks"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/files"
"github.com/iwind/TeaGo/logs"
)
// cluster -> node
type SyncAction struct {
Action
ItemActions []*configs.ItemAction
}
func (this *SyncAction) Name() string {
return "sync"
}
func (this *SyncAction) Execute() error {
for _, itemAction := range this.ItemActions {
logs.Println("[cluster]"+itemAction.Action, "'"+itemAction.ItemId+"'")
switch itemAction.Action {
case configs.ItemActionAdd:
fallthrough
case configs.ItemActionChange:
file := files.NewFile(Tea.ConfigFile(itemAction.ItemId))
dir := file.Parent()
if !dir.Exists() {
err := dir.MkdirAll()
if err != nil {
logs.Error(err)
return err
}
}
file.Write(itemAction.Item.Data)
case configs.ItemActionRemove:
file := files.NewFile(Tea.ConfigFile(itemAction.ItemId))
if file.Exists() {
file.Delete()
}
}
}
SharedManager.BuildSum()
// reload system
teahooks.Call(teahooks.EventReload)
return nil
}
func (this *SyncAction) TypeId() int8 {
return 8
}