/usr/share/gocode/src/github.com/smartystreets/goconvey/web/server/watcher/watcher.go is in golang-github-smartystreets-goconvey-dev 1.5.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | package watcher
import (
"errors"
"fmt"
"log"
"os"
"path/filepath"
"strings"
"github.com/smartystreets/goconvey/web/server/contract"
)
type Watcher struct {
files contract.FileSystem
shell contract.Shell
watched map[string]*contract.Package
root string
ambientGoPaths []string
}
func (self *Watcher) Root() string {
return self.root
}
func (self *Watcher) Adjust(root string) error {
if !self.files.Exists(root) {
return errors.New(fmt.Sprintf("Directory does not exist: '%s'", root))
}
log.Println("Adjusting to watch new root:", root)
self.root = root
self.watched = make(map[string]*contract.Package)
self.files.Walk(root, self.includeFolders)
return nil
}
func (self *Watcher) includeFolders(path string, info os.FileInfo, err error) error {
if info.IsDir() {
log.Println("Including:", path)
self.watched[path] = contract.NewPackage(path)
}
return nil
}
func (self *Watcher) Deletion(folder string) {
log.Println("Detected deletion of:", folder)
delete(self.watched, folder)
}
func (self *Watcher) Creation(folder string) {
log.Println("Detected creation of:", folder)
self.watched[folder] = contract.NewPackage(folder)
}
func (self *Watcher) Ignore(packageName string) {
for key, value := range self.watched {
if strings.HasSuffix(key, packageName) {
value.Active = false
}
}
}
func (self *Watcher) Reinstate(packageName string) {
for key, value := range self.watched {
if strings.HasSuffix(key, packageName) {
value.Active = true
}
}
}
func (self *Watcher) WatchedFolders() []*contract.Package {
i, watched := 0, make([]*contract.Package, len(self.watched))
log.Println("Number of watched folders:", len(self.watched))
for _, item := range self.watched {
watched[i] = &contract.Package{
Active: item.Active,
Path: item.Path,
Name: item.Name,
Result: contract.NewPackageResult(item.Name),
}
i++
}
return watched
}
func (self *Watcher) IsWatched(folder string) bool {
if value, exists := self.watched[folder]; exists {
return value.Active
}
return false
}
func (self *Watcher) IsIgnored(folder string) bool {
if value, exists := self.watched[folder]; exists {
return !value.Active
}
return false
}
func NewWatcher(files contract.FileSystem, shell contract.Shell) *Watcher {
self := &Watcher{}
self.files = files
self.shell = shell
self.watched = map[string]*contract.Package{}
goPath := self.shell.Getenv("GOPATH")
self.ambientGoPaths = strings.Split(goPath, entrySeparator)
return self
}
var entrySeparator = string(filepath.ListSeparator)
|