ospath.go 358 B

123456789101112131415161718192021222324
  1. package watch
  2. import (
  3. "os"
  4. "path/filepath"
  5. "strings"
  6. )
  7. func pathIsChildOf(path string, parent string) bool {
  8. relPath, err := filepath.Rel(parent, path)
  9. if err != nil {
  10. return true
  11. }
  12. if relPath == "." {
  13. return true
  14. }
  15. if filepath.IsAbs(relPath) || strings.HasPrefix(relPath, ".."+string(os.PathSeparator)) {
  16. return false
  17. }
  18. return true
  19. }