Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions pkg/remote/connparse/connparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,49 +87,59 @@ func GetConnNameFromContext(ctx context.Context) (string, error) {

// ParseURI parses a connection URI and returns the connection type, host/path, and parameters.
func ParseURI(uri string) (*Connection, error) {
split := strings.SplitN(uri, "://", 2)
split := strings.SplitN(uri, "//", 2)
var scheme string
var rest string
if len(split) > 1 {
scheme = split[0]
scheme = strings.TrimSuffix(split[0], ":")
rest = split[1]
} else {
rest = split[0]
}

var host string
var remotePath string
if scheme == "" {
scheme = ConnectionTypeWsh
if strings.HasPrefix(rest, "//") {
rest = strings.TrimPrefix(rest, "//")

parseGenericPath := func() {
split = strings.SplitN(rest, "/", 2)
host = split[0]
if len(split) > 1 {
remotePath = split[1]
} else {
split = strings.SplitN(rest, "/", 2)
host = split[0]
if len(split) > 1 {
remotePath = split[1]
} else {
remotePath = "/"
}
}
}
parseWshPath := func() {
if strings.HasPrefix(rest, "wsl://") {
host = wslConnRegex.FindString(rest)
remotePath = strings.TrimPrefix(rest, host)
} else {
parseGenericPath()
}
}

if scheme == "" {
scheme = ConnectionTypeWsh
if len(rest) != len(uri) {
// This accounts for when the uri starts with "//", which would get trimmed in the first split.
parseWshPath()
} else if strings.HasPrefix(rest, "/~") {
host = wshrpc.LocalConnName
remotePath = rest
} else {
host = ConnHostCurrent
remotePath = rest
}
} else if scheme == ConnectionTypeWsh {
parseWshPath()
} else {
if strings.HasPrefix(rest, "wsl://") {
host = wslConnRegex.FindString(rest)
remotePath = strings.TrimPrefix(rest, host)
} else {
split = strings.SplitN(rest, "/", 2)
host = split[0]
if len(split) > 1 {
remotePath = split[1]
} else {
remotePath = "/"
}
}
parseGenericPath()
}

if scheme == ConnectionTypeWsh {
Expand Down
6 changes: 2 additions & 4 deletions pkg/util/fileutil/fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ import (

func FixPath(path string) (string, error) {
if strings.HasPrefix(path, "~") {
return filepath.Join(wavebase.GetHomeDir(), path[1:]), nil
path = filepath.Join(wavebase.GetHomeDir(), path[1:])
} else if !filepath.IsAbs(path) {
log.Printf("FixPath: path is not absolute: %s", path)
path, err := filepath.Abs(path)
if err != nil {
return "", err
}
log.Printf("FixPath: fixed path: %s", path)
return path, nil
} else {
return path, nil
}
return path, nil
}

const (
Expand Down
Loading