Skip to content

Commit

Permalink
comment out file watchers
Browse files Browse the repository at this point in the history
Signed-off-by: sriv <srikanth.ddit@gmail.com>
  • Loading branch information
sriv committed Jun 29, 2021
1 parent 5208512 commit 47c71f8
Showing 1 changed file with 109 additions and 111 deletions.
220 changes: 109 additions & 111 deletions api/infoGatherer/specDetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ package infoGatherer

import (
"io/ioutil"
"path/filepath"
"sync"

"github.com/fsnotify/fsnotify"
"github.com/getgauge/gauge-proto/go/gauge_messages"
"github.com/getgauge/gauge/config"
"github.com/getgauge/gauge/gauge"
"github.com/getgauge/gauge/logger"
"github.com/getgauge/gauge/parser"
Expand Down Expand Up @@ -364,115 +362,115 @@ func (s *SpecInfoGatherer) OnConceptFileModify(file string) {
s.updateParamsCacheFromConcepts(file, s.conceptsCache.concepts[file])
}

func (s *SpecInfoGatherer) onSpecFileRemove(file string) {
logger.Debugf(false, "Spec file removed: %s", file)
s.specsCache.mutex.Lock()
defer s.specsCache.mutex.Unlock()
delete(s.specsCache.specDetails, file)
s.removeStepsFromCache(file)
}
func (s *SpecInfoGatherer) removeStepsFromCache(fileName string) {
s.stepsCache.mutex.Lock()
defer s.stepsCache.mutex.Unlock()
delete(s.stepsCache.steps, fileName)
}

func (s *SpecInfoGatherer) onConceptFileRemove(file string) {
logger.Debugf(false, "Concept file removed: %s", file)
s.conceptsCache.mutex.Lock()
defer s.conceptsCache.mutex.Unlock()
s.deleteFromConceptDictionary(file)
delete(s.conceptsCache.concepts, file)
s.removeStepsFromCache(file)
}

func (s *SpecInfoGatherer) onFileAdd(watcher *fsnotify.Watcher, file string) {
if util.IsDir(file) {
addDirToFileWatcher(watcher, file)
}
s.onFileModify(watcher, file)
}

func (s *SpecInfoGatherer) onFileModify(watcher *fsnotify.Watcher, file string) {
if util.IsSpec(file) {
s.OnSpecFileModify(file)
} else if util.IsConcept(file) {
s.OnConceptFileModify(file)
}
}

func (s *SpecInfoGatherer) onFileRemove(watcher *fsnotify.Watcher, file string) {
if util.IsSpec(file) {
s.onSpecFileRemove(file)
} else if util.IsConcept(file) {
s.onConceptFileRemove(file)
} else {
removeWatcherOn(watcher, file)
}
}

func (s *SpecInfoGatherer) onFileRename(watcher *fsnotify.Watcher, file string) {
s.onFileRemove(watcher, file)
}

func (s *SpecInfoGatherer) handleEvent(event fsnotify.Event, watcher *fsnotify.Watcher) {
s.waitGroup.Wait()

file, err := filepath.Abs(event.Name)
if err != nil {
logger.Errorf(false, "Failed to get abs file path for %s: %s", event.Name, err)
return
}
if util.IsSpec(file) || util.IsConcept(file) || util.IsDir(file) {
switch event.Op {
case fsnotify.Create:
s.onFileAdd(watcher, file)
case fsnotify.Write:
s.onFileModify(watcher, file)
case fsnotify.Rename:
s.onFileRename(watcher, file)
case fsnotify.Remove:
s.onFileRemove(watcher, file)
}
}
}

func (s *SpecInfoGatherer) watchForFileChanges() {
s.waitGroup.Add(1)

watcher, err := fsnotify.NewWatcher()
if err != nil {
logger.Errorf(false, "Error creating fileWatcher: %s", err)
}
defer watcher.Close()

done := make(chan bool)
go func() {
for {
select {
case event := <-watcher.Events:
s.handleEvent(event, watcher)
case err := <-watcher.Errors:
logger.Errorf(false, "Error event while watching specs %s", err)
}
}
}()

var allDirsToWatch []string
var specDir string

for _, dir := range s.SpecDirs {
specDir = filepath.Join(config.ProjectRoot, dir)
allDirsToWatch = append(allDirsToWatch, specDir)
allDirsToWatch = append(allDirsToWatch, util.FindAllNestedDirs(specDir)...)
}

for _, dir := range allDirsToWatch {
addDirToFileWatcher(watcher, dir)
}
s.waitGroup.Done()
<-done
}
// func (s *SpecInfoGatherer) onSpecFileRemove(file string) {
// logger.Debugf(false, "Spec file removed: %s", file)
// s.specsCache.mutex.Lock()
// defer s.specsCache.mutex.Unlock()
// delete(s.specsCache.specDetails, file)
// s.removeStepsFromCache(file)
// }
// func (s *SpecInfoGatherer) removeStepsFromCache(fileName string) {
// s.stepsCache.mutex.Lock()
// defer s.stepsCache.mutex.Unlock()
// delete(s.stepsCache.steps, fileName)
// }

// func (s *SpecInfoGatherer) onConceptFileRemove(file string) {
// logger.Debugf(false, "Concept file removed: %s", file)
// s.conceptsCache.mutex.Lock()
// defer s.conceptsCache.mutex.Unlock()
// s.deleteFromConceptDictionary(file)
// delete(s.conceptsCache.concepts, file)
// s.removeStepsFromCache(file)
// }

// func (s *SpecInfoGatherer) onFileAdd(watcher *fsnotify.Watcher, file string) {
// if util.IsDir(file) {
// addDirToFileWatcher(watcher, file)
// }
// s.onFileModify(watcher, file)
// }

// func (s *SpecInfoGatherer) onFileModify(watcher *fsnotify.Watcher, file string) {
// if util.IsSpec(file) {
// s.OnSpecFileModify(file)
// } else if util.IsConcept(file) {
// s.OnConceptFileModify(file)
// }
// }

// func (s *SpecInfoGatherer) onFileRemove(watcher *fsnotify.Watcher, file string) {
// if util.IsSpec(file) {
// s.onSpecFileRemove(file)
// } else if util.IsConcept(file) {
// s.onConceptFileRemove(file)
// } else {
// removeWatcherOn(watcher, file)
// }
// }

// func (s *SpecInfoGatherer) onFileRename(watcher *fsnotify.Watcher, file string) {
// s.onFileRemove(watcher, file)
// }

// func (s *SpecInfoGatherer) handleEvent(event fsnotify.Event, watcher *fsnotify.Watcher) {
// s.waitGroup.Wait()

// file, err := filepath.Abs(event.Name)
// if err != nil {
// logger.Errorf(false, "Failed to get abs file path for %s: %s", event.Name, err)
// return
// }
// if util.IsSpec(file) || util.IsConcept(file) || util.IsDir(file) {
// switch event.Op {
// case fsnotify.Create:
// s.onFileAdd(watcher, file)
// case fsnotify.Write:
// s.onFileModify(watcher, file)
// case fsnotify.Rename:
// s.onFileRename(watcher, file)
// case fsnotify.Remove:
// s.onFileRemove(watcher, file)
// }
// }
// }

// func (s *SpecInfoGatherer) watchForFileChanges() {
// s.waitGroup.Add(1)

// watcher, err := fsnotify.NewWatcher()
// if err != nil {
// logger.Errorf(false, "Error creating fileWatcher: %s", err)
// }
// defer watcher.Close()

// done := make(chan bool)
// go func() {
// for {
// select {
// case event := <-watcher.Events:
// s.handleEvent(event, watcher)
// case err := <-watcher.Errors:
// logger.Errorf(false, "Error event while watching specs %s", err)
// }
// }
// }()

// var allDirsToWatch []string
// var specDir string

// for _, dir := range s.SpecDirs {
// specDir = filepath.Join(config.ProjectRoot, dir)
// allDirsToWatch = append(allDirsToWatch, specDir)
// allDirsToWatch = append(allDirsToWatch, util.FindAllNestedDirs(specDir)...)
// }

// for _, dir := range allDirsToWatch {
// addDirToFileWatcher(watcher, dir)
// }
// s.waitGroup.Done()
// <-done
// }

// GetAvailableSpecs returns the list of all the specs in the gauge project
func (s *SpecInfoGatherer) GetAvailableSpecDetails(specs []string) []*SpecDetail {
Expand Down

0 comments on commit 47c71f8

Please sign in to comment.