| 28 | } |
| 29 | |
| 30 | func normalizeReference(reference string, pathSeparator rune) (normalized string, artifactType artifactType, err error) { |
| 31 | switch { |
| 32 | case strings.HasPrefix(reference, "oci://"): |
| 33 | return reference[6:], ociArtifactType, nil |
| 34 | case strings.HasPrefix(reference, "file://"): |
| 35 | uri, err := url.ParseRequestURI(reference) |
| 36 | if err != nil { |
| 37 | return "", 0, fmt.Errorf("failed to parse reference URI: %v", err) |
| 38 | } |
| 39 | var path string |
| 40 | if pathSeparator == '/' { |
| 41 | // Unix paths use forward slashes like URIs, so no need to modify |
| 42 | path = uri.Path |
| 43 | } else { |
| 44 | // Windows paths should be normalized to use backslashes |
| 45 | path = strings.ReplaceAll(uri.Path, "/", string(pathSeparator)) |
| 46 | // Remove leading slash from Windows paths if present |
| 47 | if strings.HasPrefix(path, string(pathSeparator)) { |
| 48 | path = path[1:] |
| 49 | } |
| 50 | } |
| 51 | return filepath.Clean(path), fileArtifactType, nil |
| 52 | } |
| 53 | // Treat any other reference as a local file path |
| 54 | return filepath.Clean(reference), fileArtifactType, nil |
| 55 | } |
| 56 | |
| 57 | func NewDigestedArtifactForRelease(digest string, digestAlg string) (artifact *DigestedArtifact) { |
| 58 | return &DigestedArtifact{ |