Update updates the filemap and returns if there was a change
()
| 101 | |
| 102 | // Update updates the filemap and returns if there was a change |
| 103 | func (w *watcher) Update() ([]string, []string, error) { |
| 104 | fileMap := make(map[string]os.FileInfo) |
| 105 | |
| 106 | for _, pattern := range w.Paths { |
| 107 | files, err := doublestar.Glob(pattern) |
| 108 | if err != nil { |
| 109 | return nil, nil, err |
| 110 | } |
| 111 | |
| 112 | for _, file := range files { |
| 113 | stat, err := os.Stat(file) |
| 114 | if err != nil { |
| 115 | continue |
| 116 | } |
| 117 | |
| 118 | // is excluded? |
| 119 | if w.Exclude != nil && w.Exclude.Matches(file, stat.IsDir()) { |
| 120 | continue |
| 121 | } |
| 122 | |
| 123 | fileMap[file] = stat |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | changed, deleted := w.gatherChanges(fileMap) |
| 128 | |
| 129 | // Update map |
| 130 | w.FileMap = fileMap |
| 131 | |
| 132 | return changed, deleted, nil |
| 133 | } |
| 134 | |
| 135 | func (w *watcher) gatherChanges(newState map[string]os.FileInfo) ([]string, []string) { |
| 136 | changed := make([]string, 0, 1) |
no test coverage detected