Skip to content

Commit

Permalink
update unix
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Dec 23, 2022
1 parent 380b8f3 commit 1e63214
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions cmd/oras/internal/fileref/unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ limitations under the License.

package fileref

import (
"fmt"
import
"strings"
)

// Parse parses file reference on unix.
func Parse(reference string, mediaType string) (filePath, mediatype string) {
func Parse(reference string, defaultMediaType string) (filePath, mediaType string, err error) {
if reference == "" {
return "", "", nil
}
filePath = reference
mediaType = defaultMediaType
i := strings.LastIndex(reference, ":")
if i < 0 {
return reference, mediaType
if i >= 0 {
filePath, mediaType = reference[:i], reference[i+1:]
}
if filePath == "" {
return "", "", fmt.Errorf("found empty file path in %q", reference)
}
return reference[:i], reference[i+1:]
}
return filePath, mediaType, nil
}

0 comments on commit 1e63214

Please sign in to comment.