31 lines
863 B
Go
31 lines
863 B
Go
package bundle
|
|
|
|
import (
|
|
"fmt"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
const distributorStateName = ".distributor.json"
|
|
|
|
func ValidateSourcePath(value string) error {
|
|
if value == "" {
|
|
return fmt.Errorf("source path is required")
|
|
}
|
|
if strings.Contains(value, "\\") || strings.HasPrefix(value, "/") {
|
|
return fmt.Errorf("source path %q must be a clean relative slash-separated path", value)
|
|
}
|
|
if path.Clean(value) != value {
|
|
return fmt.Errorf("source path %q must be a clean relative slash-separated path", value)
|
|
}
|
|
for _, segment := range strings.Split(value, "/") {
|
|
if segment == "" || segment == "." || segment == ".." {
|
|
return fmt.Errorf("source path %q must be a clean relative slash-separated path", value)
|
|
}
|
|
}
|
|
if path.Base(value) == ManifestName || path.Base(value) == distributorStateName {
|
|
return fmt.Errorf("%q is reserved", value)
|
|
}
|
|
return nil
|
|
}
|