#87 fixed
This commit is contained in:
parent
f1bd8e9357
commit
bf55c51676
@ -23,16 +23,13 @@ var out BufferOut
|
|||||||
|
|
||||||
// Project defines the informations of a single project
|
// Project defines the informations of a single project
|
||||||
type Project struct {
|
type Project struct {
|
||||||
settings.Settings
|
settings.Settings `yaml:"-" json:"-"`
|
||||||
parent *Blueprint
|
parent *Blueprint
|
||||||
path string
|
path string
|
||||||
tools tools
|
tools tools
|
||||||
wr sync.WaitGroup
|
|
||||||
watcher *fsnotify.Watcher
|
|
||||||
channel chan bool
|
|
||||||
exit chan os.Signal
|
|
||||||
base string
|
base string
|
||||||
LastChangedOn time.Time `yaml:"-" json:"-"`
|
paths []string
|
||||||
|
lastChangedOn time.Time
|
||||||
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"`
|
Environment map[string]string `yaml:"environment,omitempty" json:"environment,omitempty"`
|
||||||
@ -58,35 +55,36 @@ func (p *Project) watchByNotify() {
|
|||||||
}()
|
}()
|
||||||
p.cmd("before", true)
|
p.cmd("before", true)
|
||||||
go p.routines(&wr, channel, watcher, "")
|
go p.routines(&wr, channel, watcher, "")
|
||||||
p.LastChangedOn = time.Now().Truncate(time.Second)
|
p.lastChangedOn = time.Now().Truncate(time.Second)
|
||||||
L:
|
L:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case event := <-watcher.Events:
|
case event := <-watcher.Events:
|
||||||
if time.Now().Truncate(time.Second).After(p.LastChangedOn) {
|
if time.Now().Truncate(time.Second).After(p.lastChangedOn) {
|
||||||
if event.Op&fsnotify.Chmod == fsnotify.Chmod {
|
p.lastChangedOn = time.Now().Truncate(time.Second)
|
||||||
continue
|
if file, err := os.Lstat(event.Name); err == nil {
|
||||||
}
|
if file.Size() > 0 {
|
||||||
if index := strings.Index(filepath.Ext(event.Name), "__"); index != -1 {
|
p.lastChangedOn = time.Now().Truncate(time.Second)
|
||||||
continue
|
ext := filepath.Ext(event.Name)
|
||||||
}
|
if inArray(ext, p.Watcher.Exts) {
|
||||||
ext := filepath.Ext(event.Name)
|
if p.Cmds.Run {
|
||||||
if inArray(filepath.Ext(event.Name), p.Watcher.Exts) {
|
close(channel)
|
||||||
if p.Cmds.Run {
|
channel = make(chan bool)
|
||||||
close(channel)
|
}
|
||||||
channel = make(chan bool)
|
// repeat the initial cycle
|
||||||
|
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", style.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), style.Magenta.Bold(event.Name))
|
||||||
|
out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + event.Name}
|
||||||
|
p.stamp("log", out, msg, "")
|
||||||
|
// check if is deleted
|
||||||
|
if event.Op&fsnotify.Remove == fsnotify.Remove {
|
||||||
|
watcher.Remove(event.Name)
|
||||||
|
go p.routines(&wr, channel, watcher, "")
|
||||||
|
} else {
|
||||||
|
go p.routines(&wr, channel, watcher, event.Name)
|
||||||
|
}
|
||||||
|
p.lastChangedOn = time.Now().Truncate(time.Second)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// repeat the initial cycle
|
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", style.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), style.Magenta.Bold(event.Name))
|
|
||||||
out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + event.Name}
|
|
||||||
p.stamp("log", out, msg, "")
|
|
||||||
// check if is deleted
|
|
||||||
if event.Op&fsnotify.Remove == fsnotify.Remove {
|
|
||||||
go p.routines(&wr, channel, watcher, "")
|
|
||||||
} else {
|
|
||||||
go p.routines(&wr, channel, watcher, event.Name)
|
|
||||||
}
|
|
||||||
p.LastChangedOn = time.Now().Truncate(time.Second)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case err := <-watcher.Errors:
|
case err := <-watcher.Errors:
|
||||||
@ -113,13 +111,13 @@ func (p *Project) watchByPolling() {
|
|||||||
}()
|
}()
|
||||||
p.cmd("before", true)
|
p.cmd("before", true)
|
||||||
go p.routines(&wr, channel, watcher, "")
|
go p.routines(&wr, channel, watcher, "")
|
||||||
p.LastChangedOn = time.Now().Truncate(time.Second)
|
p.lastChangedOn = time.Now().Truncate(time.Second)
|
||||||
walk := func(changed string, info os.FileInfo, err error) error {
|
walk := func(changed string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if !watcher.isWatching(changed) {
|
} else if !watcher.isWatching(changed) {
|
||||||
return nil
|
return nil
|
||||||
} else if !info.ModTime().Truncate(time.Second).After(p.LastChangedOn) {
|
} else if !info.ModTime().Truncate(time.Second).After(p.lastChangedOn) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if index := strings.Index(filepath.Ext(changed), "__"); index != -1 {
|
if index := strings.Index(filepath.Ext(changed), "__"); index != -1 {
|
||||||
@ -131,7 +129,7 @@ func (p *Project) watchByPolling() {
|
|||||||
close(channel)
|
close(channel)
|
||||||
channel = make(chan bool)
|
channel = make(chan bool)
|
||||||
}
|
}
|
||||||
p.LastChangedOn = time.Now().Truncate(time.Second)
|
p.lastChangedOn = time.Now().Truncate(time.Second)
|
||||||
// repeat the initial cycle
|
// repeat the initial cycle
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", style.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), style.Magenta.Bold(changed))
|
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", style.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), style.Magenta.Bold(changed))
|
||||||
out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + changed}
|
out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + changed}
|
||||||
@ -226,6 +224,7 @@ func (p *Project) walk(watcher watcher) error {
|
|||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
}
|
}
|
||||||
if inArray(filepath.Ext(path), p.Watcher.Exts) {
|
if inArray(filepath.Ext(path), p.Watcher.Exts) {
|
||||||
|
p.paths = append(p.paths, path)
|
||||||
files++
|
files++
|
||||||
} else {
|
} else {
|
||||||
folders++
|
folders++
|
||||||
|
Loading…
Reference in New Issue
Block a user