minor cleanup
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
package folder
|
|
||||||
16
main.go
16
main.go
@@ -115,8 +115,6 @@ func (s *Script) Stop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Script) Restart() error {
|
func (s *Script) Restart() error {
|
||||||
println("Restarting script")
|
|
||||||
|
|
||||||
s.mutex.Lock()
|
s.mutex.Lock()
|
||||||
|
|
||||||
s.isRestarting = true
|
s.isRestarting = true
|
||||||
@@ -311,10 +309,18 @@ func main() {
|
|||||||
// iterate over every letter in the pattern
|
// iterate over every letter in the pattern
|
||||||
for _, p := range config.Pattern {
|
for _, p := range config.Pattern {
|
||||||
if string(p) == "{" {
|
if string(p) == "{" {
|
||||||
|
if inMatch {
|
||||||
|
log.Fatal("unmatched { in pattern")
|
||||||
|
}
|
||||||
|
|
||||||
inMatch = true
|
inMatch = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(p) == "}" {
|
if string(p) == "}" {
|
||||||
|
if !inMatch {
|
||||||
|
log.Fatal("unmatched } in pattern")
|
||||||
|
}
|
||||||
|
|
||||||
inMatch = false
|
inMatch = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,6 +334,10 @@ func main() {
|
|||||||
currentPattern += string(p)
|
currentPattern += string(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if inMatch {
|
||||||
|
log.Fatal("unmatched } in pattern")
|
||||||
|
}
|
||||||
|
|
||||||
if currentPattern != "" {
|
if currentPattern != "" {
|
||||||
paternArray = append(paternArray, currentPattern)
|
paternArray = append(paternArray, currentPattern)
|
||||||
}
|
}
|
||||||
@@ -411,6 +421,4 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
script.Wait()
|
script.Wait()
|
||||||
|
|
||||||
log.Println("Script finished")
|
|
||||||
}
|
}
|
||||||
|
|||||||
31
watcher.go
31
watcher.go
@@ -1,14 +1,10 @@
|
|||||||
// There is some dead code in here because I pulled out the parts I needed to get it working, deal with this later lol.
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/bmatcuk/doublestar"
|
"github.com/bmatcuk/doublestar"
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
@@ -54,7 +50,6 @@ type FileWatcher interface {
|
|||||||
Close() error
|
Close() error
|
||||||
AddFiles() error
|
AddFiles() error
|
||||||
add(path string) error
|
add(path string) error
|
||||||
Watch(jobs chan<- string)
|
|
||||||
getConfig() *WatcherConfig
|
getConfig() *WatcherConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,32 +66,6 @@ func (n NotifyWatcher) AddFiles() error {
|
|||||||
return addFiles(n)
|
return addFiles(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n NotifyWatcher) Watch(jobs chan<- string) {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case ev := <-n.watcher.Events:
|
|
||||||
if ev.Op&fsnotify.Remove == fsnotify.Remove || ev.Op&fsnotify.Write == fsnotify.Write || ev.Op&fsnotify.Create == fsnotify.Create {
|
|
||||||
// Assume it is a directory and track it.
|
|
||||||
if directoryShouldBeTracked(n.cfg, ev.Name) {
|
|
||||||
n.watcher.Add(ev.Name)
|
|
||||||
}
|
|
||||||
if pathMatches(n.cfg, ev.Name) {
|
|
||||||
jobs <- ev.Name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case err := <-n.watcher.Errors:
|
|
||||||
if v, ok := err.(*os.SyscallError); ok {
|
|
||||||
if v.Err == syscall.EINTR {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
log.Fatal("watcher.Error: SyscallError:", v)
|
|
||||||
}
|
|
||||||
log.Fatal("watcher.Error:", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n NotifyWatcher) add(path string) error {
|
func (n NotifyWatcher) add(path string) error {
|
||||||
return n.watcher.Add(path)
|
return n.watcher.Add(path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "zqdgr",
|
"name": "zqdgr",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"description": "zqdgr is a quick and dirty Golang runner",
|
"description": "zqdgr is a quick and dirty Golang runner",
|
||||||
"author": "juls0730",
|
"author": "juls0730",
|
||||||
"license": "BSL-1.0",
|
"license": "BSL-1.0",
|
||||||
@@ -13,8 +13,5 @@
|
|||||||
"build": "go build -o zqdgr",
|
"build": "go build -o zqdgr",
|
||||||
"dev": "sleep 5; echo 'test' && sleep 2 && echo 'test2'"
|
"dev": "sleep 5; echo 'test' && sleep 2 && echo 'test2'"
|
||||||
},
|
},
|
||||||
"pattern": "**/*.go",
|
"pattern": "**/*.go"
|
||||||
"excluded_dirs": [
|
|
||||||
"folder"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user