2026-06-01 20:52:23 +00:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-04 00:40:17 +00:00
|
|
|
if path.Base(value) == ManifestName || path.Base(value) == distributorStateName {
|
2026-06-01 20:52:23 +00:00
|
|
|
return fmt.Errorf("%q is reserved", value)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|