Add adds a filter rule with include or exclude status indicated
(Include bool, glob string)
| 312 | |
| 313 | // Add adds a filter rule with include or exclude status indicated |
| 314 | func (f *Filter) Add(Include bool, glob string) error { |
| 315 | isDirRule := strings.HasSuffix(glob, "/") |
| 316 | isFileRule := !isDirRule |
| 317 | // Make excluding "dir/" equivalent to excluding "dir/**" |
| 318 | if isDirRule && !Include { |
| 319 | glob += "**" |
| 320 | } |
| 321 | if strings.Contains(glob, "**") { |
| 322 | isDirRule, isFileRule = true, true |
| 323 | } |
| 324 | re, err := GlobPathToRegexp(glob, f.Opt.IgnoreCase) |
| 325 | if err != nil { |
| 326 | return err |
| 327 | } |
| 328 | if isFileRule { |
| 329 | f.fileRules.add(Include, re) |
| 330 | // If include rule work out what directories are needed to scan |
| 331 | // if exclude rule, we can't rule anything out |
| 332 | // Unless it is `*` which matches everything |
| 333 | // NB ** and /** are DirRules |
| 334 | if Include || glob == "*" { |
| 335 | err = f.addDirGlobs(Include, glob) |
| 336 | if err != nil { |
| 337 | return err |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | if isDirRule { |
| 342 | f.dirRules.add(Include, re) |
| 343 | } |
| 344 | return nil |
| 345 | } |
| 346 | |
| 347 | // AddRule adds a filter rule with include/exclude indicated by the prefix |
| 348 | // |