Handle windows path and do not perform translation for url type of filesystem

This commit is contained in:
Harshavardhana
2015-06-11 21:10:49 -07:00
parent 114299070c
commit 1516549e66
2 changed files with 18 additions and 15 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ var (
// mc configuration related constants
const (
mcConfigDir = ".mc/"
mcConfigWindowsDir = "mc/"
mcConfigWindowsDir = "mc\\"
mcConfigFile = "config.json"
)
+17 -14
View File
@@ -111,27 +111,30 @@ func Parse(urlStr string) (*URL, error) {
// String convert URL into its canonical form
func (u *URL) String() string {
var buf bytes.Buffer
if u.Scheme != "" {
// if fileystem no translation needed, return as is
if u.Type == Filesystem {
return u.Path
}
// if Object convert from any non standard paths to a supported URL path style
if u.Type == Object {
buf.WriteString(u.Scheme)
buf.WriteByte(':')
}
if u.Scheme != "" || u.Host != "" {
buf.WriteString("//")
if h := u.Host; h != "" {
buf.WriteString(h)
}
}
switch runtime.GOOS {
case "windows":
if u.Path != "" && u.Path[0] != '\\' && u.Host != "" && u.Path[0] != '/' {
buf.WriteByte('/')
switch runtime.GOOS {
case "windows":
if u.Path != "" && u.Path[0] != '\\' && u.Host != "" && u.Path[0] != '/' {
buf.WriteByte('/')
}
buf.WriteString(strings.Replace(u.Path, "\\", "/", -1))
default:
if u.Path != "" && u.Path[0] != '/' && u.Host != "" {
buf.WriteByte('/')
}
buf.WriteString(u.Path)
}
buf.WriteString(strings.Replace(u.Path, "\\", "/", -1))
default:
if u.Path != "" && u.Path[0] != '/' && u.Host != "" {
buf.WriteByte('/')
}
buf.WriteString(u.Path)
}
return buf.String()
}