some bug fixes

This commit is contained in:
ston1th 2019-05-05 19:06:51 +02:00
commit 0e914c629e
16 changed files with 179 additions and 52 deletions

View file

@ -3,6 +3,7 @@
package core
import (
"sync"
"time"
)
@ -10,6 +11,13 @@ const (
fileFmt = "20060102_150405"
)
var m sync.Mutex
func FileName() string {
m.Lock()
defer func() {
time.Sleep(time.Millisecond * 1100)
m.Unlock()
}()
return time.Now().Format(fileFmt)
}

View file

@ -1,39 +0,0 @@
// Copyright (C) 2019 Marius Schellenberger
package core
import (
"errors"
"os/exec"
"time"
)
func Timeout(cmd *exec.Cmd, t time.Duration) (output []byte, err error) {
done := make(chan error)
out := make(chan []byte)
go func() {
o, e := cmd.Output()
done <- e
out <- o
}()
select {
case <-time.After(t):
e := cmd.Process.Kill()
<-out
if e != nil {
<-done
err = e
return
}
err = <-done
case e := <-done:
exerr, ok := e.(*exec.ExitError)
if ok {
err = errors.New(e.Error() + "\n" + string(exerr.Stderr))
} else {
err = e
}
output = <-out
}
return
}

View file

@ -24,6 +24,7 @@ type Path struct {
Name string
Abs string
Flag bool
Scan bool
}
type Paths []Path
@ -33,15 +34,17 @@ func (p Paths) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p Paths) Less(i, j int) bool { return p[i].Name < p[j].Name }
type Config struct {
RunDir string `json:"run_dir,omitempty"`
DataDir string `json:"-"`
User string `json:"user,omitempty"`
Group string `json:"group,omitempty"`
ListenAddr string `json:"listen_addr,omitempty"`
LogFile string `json:"log_file,omitempty"`
Version string `json:"-"`
Secret string `json:"secret,omitempty"`
Foreground bool `json:"foreground,omitempty"`
SecureCookie bool `json:"secure_cookie,omitempty"`
Debug bool `json:"debug,omitempty"`
RunDir string `json:"run_dir,omitempty"`
DataDir string `json:"-"`
User string `json:"user,omitempty"`
Group string `json:"group,omitempty"`
ListenAddr string `json:"listen_addr,omitempty"`
LogFile string `json:"log_file,omitempty"`
Version string `json:"-"`
Secret string `json:"secret,omitempty"`
Langs []string `json:"langs,omitempty"`
CMDTimeout int `json:"cmd_timeout,omitempty"`
Foreground bool `json:"foreground,omitempty"`
SecureCookie bool `json:"secure_cookie,omitempty"`
Debug bool `json:"debug,omitempty"`
}