Skip to content

Commit a14e005

Browse files
committed
runner/v3: use more signal to detect a file has changed
1 parent 51511a6 commit a14e005

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

internal/runner/runner.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,17 @@ func (s *Runner) monitorGitDir(ctx context.Context, dir string) <-chan string {
591591
}
592592

593593
func (s *Runner) monitorWorkDirScanner(ctx context.Context) <-chan string {
594+
type memoFile struct {
595+
time time.Time
596+
size int64
597+
}
594598
triggereds := make(chan string, 1)
595599
triggereds <- ""
596600
go func() {
597601
defer close(triggereds)
598602
t := time.NewTicker(50 * time.Millisecond)
599603
defer t.Stop()
600-
memo := make(map[string]time.Time)
604+
memo := make(map[string]memoFile)
601605
for {
602606
select {
603607
case <-ctx.Done():
@@ -624,15 +628,23 @@ func (s *Runner) monitorWorkDirScanner(ctx context.Context) <-chan string {
624628
continue
625629
}
626630
mtime := info.ModTime()
627-
memoMTime, ok := memo[path]
631+
fsize := info.Size()
632+
mf, ok := memo[path]
628633
if !ok {
629-
memo[path] = mtime
630-
memoMTime = mtime
634+
memo[path] = memoFile{
635+
time: mtime,
636+
size: fsize,
637+
}
638+
mf = memo[path]
631639
}
632-
if mtime.Equal(memoMTime) {
640+
if mtime.Equal(mf.time) && fsize == mf.size {
633641
continue
634642
}
635-
memo[path] = mtime
643+
fmt.Println(">>>> file changed:", path)
644+
memo[path] = memoFile{
645+
time: mtime,
646+
size: fsize,
647+
}
636648
triggereds <- path
637649
}
638650
return nil

0 commit comments

Comments
 (0)