centralise special path prefix check

This commit is contained in:
sentriz
2023-12-22 19:48:14 +00:00
parent 552aa3afb1
commit b5de0b3b84
3 changed files with 9 additions and 2 deletions

View File

@@ -54,3 +54,8 @@ func First(path ...string) (string, error) {
}
return "", err
}
// HasPrefix checks a path has a prefix, making sure to respect path boundaries. So that /aa & /a does not match, but /a/a & /a does.
func HasPrefix(p, prefix string) bool {
return p == prefix || strings.HasPrefix(p, filepath.Clean(prefix)+string(filepath.Separator))
}