Load and parse a file. The returned error may be of type *ParseError in which case a file was loaded from disk but the patterns could not be parsed. In this case the contents of the file are nonetheless available in the Lines() method.
(file string)
| 172 | // parsed. In this case the contents of the file are nonetheless available |
| 173 | // in the Lines() method. |
| 174 | func (m *Matcher) Load(file string) error { |
| 175 | m.mut.Lock() |
| 176 | defer m.mut.Unlock() |
| 177 | |
| 178 | if m.changeDetector.Seen(m.fs, file) && !m.changeDetector.Changed() { |
| 179 | return nil |
| 180 | } |
| 181 | |
| 182 | fd, info, err := loadIgnoreFile(m.fs, file) |
| 183 | if err != nil { |
| 184 | m.parseLocked(&bytes.Buffer{}, file) |
| 185 | return err |
| 186 | } |
| 187 | defer fd.Close() |
| 188 | |
| 189 | m.changeDetector.Reset() |
| 190 | |
| 191 | err = m.parseLocked(fd, file) |
| 192 | // If we failed to parse, don't cache, as next time Load is called |
| 193 | // we'll pretend it's all good. |
| 194 | if err == nil { |
| 195 | m.changeDetector.Remember(m.fs, file, info.ModTime()) |
| 196 | } |
| 197 | return err |
| 198 | } |
| 199 | |
| 200 | // Load and parse an io.Reader. See Load() for notes on the returned error. |
| 201 | func (m *Matcher) Parse(r io.Reader, file string) error { |