check broken symbolic

This commit is contained in:
asoseil 2018-02-09 17:50:31 +01:00
parent 83134f9b8d
commit 13beb532f9
1 changed files with 21 additions and 25 deletions

View File

@ -26,18 +26,22 @@ var (
// Watch info // Watch info
type Watch struct { type Watch struct {
Exts []string `yaml:"exts" json:"exts"`
Paths []string `yaml:"paths" json:"paths"` Paths []string `yaml:"paths" json:"paths"`
Exts []string `yaml:"extensions" json:"extensions"`
IgnoredExts []string `yaml:"ignored_extensions,omitempty" json:"ignored_extensions,omitempty"`
IgnoredPaths []string `yaml:"ignored_paths,omitempty" json:"ignored_paths,omitempty"`
Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"` Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"`
Hidden bool `yaml:"skip_hidden,omitempty" json:"skip_hidden,omitempty"` Hidden bool `yaml:"hidden,omitempty" json:"hidden,omitempty"`
Ignore Ignore `yaml:"ignore,omitempty" json:"ignore,omitempty"`
}
type Ignore struct{
Exts []string `yaml:"exts,omitempty" json:"exts,omitempty"`
Paths []string `yaml:"paths,omitempty" json:"paths,omitempty"`
} }
// Command fields // Command fields
type Command struct { type Command struct {
Cmd string `yaml:"cmd" json:"cmd"`
Type string `yaml:"type" json:"type"` Type string `yaml:"type" json:"type"`
Cmd string `yaml:"command" json:"command"`
Path string `yaml:"path,omitempty" json:"path,omitempty"` Path string `yaml:"path,omitempty" json:"path,omitempty"`
Global bool `yaml:"global,omitempty" json:"global,omitempty"` Global bool `yaml:"global,omitempty" json:"global,omitempty"`
Output bool `yaml:"output,omitempty" json:"output,omitempty"` Output bool `yaml:"output,omitempty" json:"output,omitempty"`
@ -47,21 +51,21 @@ type Command struct {
type Project struct { type Project struct {
parent *Realize parent *Realize
watcher FileWatcher watcher FileWatcher
init bool
exit chan os.Signal
stop chan bool stop chan bool
exit chan os.Signal
paths []string
last last
files int64 files int64
folders int64 folders int64
last last init bool
paths []string
Name string `yaml:"name" json:"name"` Name string `yaml:"name" json:"name"`
Path string `yaml:"path" json:"path"` Path string `yaml:"path" json:"path"`
Environment map[string]string `yaml:"environment,omitempty" json:"environment,omitempty"` Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
Tools Tools `yaml:"commands" json:"commands"`
Args []string `yaml:"args,omitempty" json:"args,omitempty"` Args []string `yaml:"args,omitempty" json:"args,omitempty"`
Tools Tools `yaml:"tools" json:"tools"`
Watcher Watch `yaml:"watcher" json:"watcher"` Watcher Watch `yaml:"watcher" json:"watcher"`
Buffer Buffer `yaml:"-" json:"buffer"` Buffer Buffer `yaml:"-" json:"buffer"`
ErrorOutputPattern string `yaml:"errorOutputPattern,omitempty" json:"errorOutputPattern,omitempty"` ErrPattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"`
} }
// Last is used to save info about last file changed // Last is used to save info about last file changed
@ -112,7 +116,7 @@ func (p *Project) Before() {
// setup go tools // setup go tools
p.Tools.Setup() p.Tools.Setup()
// set env const // set env const
for key, item := range p.Environment { for key, item := range p.Env {
if err := os.Setenv(key, item); err != nil { if err := os.Setenv(key, item); err != nil {
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error(), Type: "Env error", Stream: ""}) p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error(), Type: "Env error", Stream: ""})
} }
@ -352,14 +356,13 @@ func (p *Project) Validate(path string, fcheck bool) bool {
return false return false
} }
// check ignored // check ignored
for _, v := range p.Watcher.IgnoredExts { for _, v := range p.Watcher.Ignore.Exts {
if v == e { if v == e {
return false return false
} }
} }
// supported extensions // supported extensions
for index, v := range p.Watcher.Exts{ for index, v := range p.Watcher.Exts{
println(v)
if e == v { if e == v {
break break
} }
@ -370,7 +373,7 @@ func (p *Project) Validate(path string, fcheck bool) bool {
} }
separator := string(os.PathSeparator) separator := string(os.PathSeparator)
// supported paths // supported paths
for _, v := range p.Watcher.IgnoredPaths { for _, v := range p.Watcher.Ignore.Paths {
s := append([]string{p.Path}, strings.Split(v, separator)...) s := append([]string{p.Path}, strings.Split(v, separator)...)
abs, _ := filepath.Abs(filepath.Join(s...)) abs, _ := filepath.Abs(filepath.Join(s...))
if path == abs || strings.HasPrefix(path, abs+separator) { if path == abs || strings.HasPrefix(path, abs+separator) {
@ -380,16 +383,9 @@ func (p *Project) Validate(path string, fcheck bool) bool {
// file check // file check
if fcheck { if fcheck {
fi, err := os.Stat(path) fi, err := os.Stat(path)
if err != nil { if err != nil || fi.Mode()&os.ModeSymlink != 0 || !fi.IsDir() && ext(path) == "" || fi.Size() <= 0{
return false return false
} }
if !fi.IsDir() && ext(path) == "" {
return false
}
if fi.Size() > 0 {
return true
}
return false
} }
return true return true
@ -572,7 +568,7 @@ func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err
isErrorText := func(string) bool { isErrorText := func(string) bool {
return false return false
} }
errRegexp, err := regexp.Compile(p.ErrorOutputPattern) errRegexp, err := regexp.Compile(p.ErrPattern)
if err != nil { if err != nil {
r.Err = err r.Err = err
stream <- r stream <- r