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