PackageManager just because
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.1 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package Filesystem
  2. import (
  3. "regexp"
  4. "strings"
  5. "PackageManager/Variables"
  6. )
  7. var (
  8. PruneRegex []*regexp.Regexp
  9. IgnoreRegex []*regexp.Regexp
  10. )
  11. func init() {
  12. var err error
  13. err = InitPruneRegex()
  14. if err != nil {
  15. panic(err)
  16. }
  17. err = InitIgnoreRegex()
  18. if err != nil {
  19. panic(err)
  20. }
  21. }
  22. func InitPruneRegex() error {
  23. var (
  24. r *regexp.Regexp
  25. s string
  26. err error
  27. )
  28. for _, s = range Variables.PruneRegexPaths {
  29. r, err = regexp.Compile(strings.Replace(s, "^/", "^"+Variables.RootDir, 1))
  30. if err != nil {
  31. return err
  32. }
  33. PruneRegex = append(PruneRegex, r)
  34. }
  35. return nil
  36. }
  37. func InitIgnoreRegex() error {
  38. var (
  39. r *regexp.Regexp
  40. s string
  41. err error
  42. )
  43. for _, s = range Variables.IgnoreRegexPaths {
  44. r, err = regexp.Compile(strings.Replace(s, "^/", "^"+Variables.RootDir, 1))
  45. if err != nil {
  46. return err
  47. }
  48. IgnoreRegex = append(IgnoreRegex, r)
  49. }
  50. return nil
  51. }
  52. func matchAny(p string, a []*regexp.Regexp) bool {
  53. var (
  54. regex *regexp.Regexp
  55. )
  56. for _, regex = range a {
  57. if regex.MatchString(p) {
  58. return true
  59. }
  60. }
  61. return false
  62. }