forked from oras-project/oras
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cross-platform support on path (oras-project#65)
- Parse paths wisely for unix and win - Support disk letter `C:\` on win - Paths are auto-cleaned on CLI
- Loading branch information
Showing
3 changed files
with
47 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// +build !windows | ||
|
||
package main | ||
|
||
import "strings" | ||
|
||
func parseFileRef(ref string, mediaType string) (string, string) { | ||
i := strings.LastIndex(ref, ":") | ||
if i < 0 { | ||
return ref, mediaType | ||
} | ||
return ref[:i], ref[i+1:] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
"unicode" | ||
) | ||
|
||
// parseFileRef parse file reference on windows. | ||
// Windows systems does not allow ':' in the file path except for drive letter. | ||
func parseFileRef(ref string, mediaType string) (string, string) { | ||
i := strings.Index(ref, ":") | ||
if i < 0 { | ||
return ref, mediaType | ||
} | ||
|
||
// In case it is C:\ | ||
if i == 1 && len(ref) > 2 && ref[2] == '\\' && unicode.IsLetter(rune(ref[0])) { | ||
i = strings.Index(ref[3:], ":") | ||
if i < 0 { | ||
return ref, mediaType | ||
} | ||
i += 3 | ||
} | ||
|
||
return ref[:i], ref[i+1:] | ||
} |