action.Error
This commit is contained in:
parent
130d4fedc7
commit
1dbb38b822
15
main.go
15
main.go
@ -46,8 +46,9 @@ type ActionConfig struct {
|
||||
OnSuccess []ActionConfig `yaml:"onSuccess"`
|
||||
OnError []ActionConfig `yaml:"onError"`
|
||||
|
||||
_dirConf *DirectoryConfig
|
||||
Parent *ActionConfig `yaml:"-"`
|
||||
Directory *DirectoryConfig `yaml:"-"`
|
||||
Parent *ActionConfig `yaml:"-"`
|
||||
Error error `yaml:"-"`
|
||||
}
|
||||
|
||||
type DirectoryConfig struct {
|
||||
@ -175,7 +176,7 @@ func startWatcher(directory *DirectoryConfig) {
|
||||
}
|
||||
if directory._regex == nil || directory._regexMatches != nil {
|
||||
for _, action := range directory.Actions {
|
||||
action._dirConf = directory
|
||||
action.Directory = directory
|
||||
contin, _ := runAction(&action, eventInfo, nil)
|
||||
if !contin {
|
||||
break
|
||||
@ -241,10 +242,11 @@ func runAction(action *ActionConfig, eventInfo notify.EventInfo, ctx actionCtx)
|
||||
|
||||
if err != nil {
|
||||
add2Ctx(action, ctx, "error", err.Error())
|
||||
action.Error = err
|
||||
|
||||
log.Printf("path: %s; action: %s; error %s", eventInfo.Path(), action.Id, err)
|
||||
for _, aE := range action.OnError {
|
||||
aE._dirConf = action._dirConf
|
||||
aE.Directory = action.Directory
|
||||
aE.Parent = action
|
||||
_c, _ := runAction(&aE, eventInfo, ctx)
|
||||
contin = contin && _c
|
||||
@ -254,7 +256,7 @@ func runAction(action *ActionConfig, eventInfo notify.EventInfo, ctx actionCtx)
|
||||
}
|
||||
} else {
|
||||
for _, aS := range action.OnSuccess {
|
||||
aS._dirConf = action._dirConf
|
||||
aS.Directory = action.Directory
|
||||
aS.Parent = action
|
||||
_c, errS := runAction(&aS, eventInfo, ctx)
|
||||
contin = contin && _c
|
||||
@ -453,7 +455,8 @@ func tpl2String(tpl string, action *ActionConfig, eventInfo notify.EventInfo, ct
|
||||
"filename": filepath.Base(p),
|
||||
"event": eventInfo.Event().String(),
|
||||
"action": action,
|
||||
"regexMatches": action._dirConf._regexMatches,
|
||||
"directory": action.Directory,
|
||||
"regexMatches": action.Directory._regexMatches,
|
||||
"context": ctx,
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user