This file is indexed.

/usr/share/gocode/src/github.com/smartystreets/goconvey/web/server/watcher/scanner.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
package watcher

import (
	"log"
	"os"

	"github.com/smartystreets/goconvey/web/server/contract"
)

type Scanner struct {
	fs                 contract.FileSystem
	watcher            contract.Watcher
	root               string
	previous           int64
	latestFolders      map[string]bool
	preExistingFolders map[string]bool
}

func (self *Scanner) Scan() bool {
	rootIsNew := self.recordCurrentRoot()
	checksum, folders := self.analyzeCurrentFileSystemState()
	if !rootIsNew {
		self.notifyWatcherOfChangesInFolderStructure(folders)
	}
	self.preExistingFolders = folders
	return self.latestTestResultsAreStale(checksum)
}

func (self *Scanner) recordCurrentRoot() (changed bool) {
	root := self.watcher.Root()
	if root != self.root {
		log.Println("Updating root in scanner:", root)
		self.root = root
		return true
	}
	return false
}

func (self *Scanner) analyzeCurrentFileSystemState() (checksum int64, folders map[string]bool) {
	folders = make(map[string]bool)

	self.fs.Walk(self.root, func(path string, info os.FileInfo, err error) error {
		step := newWalkStep(self.root, path, info, self.watcher)
		step.IncludeIn(folders)
		checksum += step.Sum()
		return nil
	})
	return checksum, folders
}

func (self *Scanner) notifyWatcherOfChangesInFolderStructure(latest map[string]bool) {
	self.accountForDeletedFolders(latest)
	self.accountForNewFolders(latest)
}
func (self *Scanner) accountForDeletedFolders(latest map[string]bool) {
	for folder, _ := range self.preExistingFolders {
		if _, exists := latest[folder]; !exists {
			self.watcher.Deletion(folder)
		}
	}
}
func (self *Scanner) accountForNewFolders(latest map[string]bool) {
	for folder, _ := range latest {
		if _, exists := self.preExistingFolders[folder]; !exists {
			self.watcher.Creation(folder)
		}
	}
}

func (self *Scanner) latestTestResultsAreStale(checksum int64) bool {
	defer func() { self.previous = checksum }()
	return self.previous != checksum
}

func NewScanner(fs contract.FileSystem, watcher contract.Watcher) *Scanner {
	self := &Scanner{}
	self.fs = fs
	self.watcher = watcher
	self.latestFolders = make(map[string]bool)
	self.preExistingFolders = make(map[string]bool)
	self.rememberCurrentlyWatchedFolders()

	return self
}
func (self *Scanner) rememberCurrentlyWatchedFolders() {
	for _, item := range self.watcher.WatchedFolders() {
		self.preExistingFolders[item.Path] = true
	}
}