mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-15 01:32:17 +01:00
Fix connparse for wsl (#1843)
Co-authored-by: sawka <mike@commandline.dev>
This commit is contained in:
parent
b9f703f2b5
commit
270855f9cf
@ -87,11 +87,11 @@ func GetConnNameFromContext(ctx context.Context) (string, error) {
|
|||||||
|
|
||||||
// ParseURI parses a connection URI and returns the connection type, host/path, and parameters.
|
// ParseURI parses a connection URI and returns the connection type, host/path, and parameters.
|
||||||
func ParseURI(uri string) (*Connection, error) {
|
func ParseURI(uri string) (*Connection, error) {
|
||||||
split := strings.SplitN(uri, "://", 2)
|
split := strings.SplitN(uri, "//", 2)
|
||||||
var scheme string
|
var scheme string
|
||||||
var rest string
|
var rest string
|
||||||
if len(split) > 1 {
|
if len(split) > 1 {
|
||||||
scheme = split[0]
|
scheme = strings.TrimSuffix(split[0], ":")
|
||||||
rest = split[1]
|
rest = split[1]
|
||||||
} else {
|
} else {
|
||||||
rest = split[0]
|
rest = split[0]
|
||||||
@ -99,10 +99,13 @@ func ParseURI(uri string) (*Connection, error) {
|
|||||||
|
|
||||||
var host string
|
var host string
|
||||||
var remotePath string
|
var remotePath string
|
||||||
if scheme == "" {
|
|
||||||
scheme = ConnectionTypeWsh
|
parseGenericPath := func() {
|
||||||
if strings.HasPrefix(rest, "//") {
|
split = strings.SplitN(rest, "/", 2)
|
||||||
rest = strings.TrimPrefix(rest, "//")
|
host = split[0]
|
||||||
|
if len(split) > 1 {
|
||||||
|
remotePath = split[1]
|
||||||
|
} else {
|
||||||
split = strings.SplitN(rest, "/", 2)
|
split = strings.SplitN(rest, "/", 2)
|
||||||
host = split[0]
|
host = split[0]
|
||||||
if len(split) > 1 {
|
if len(split) > 1 {
|
||||||
@ -110,6 +113,22 @@ func ParseURI(uri string) (*Connection, error) {
|
|||||||
} else {
|
} else {
|
||||||
remotePath = "/"
|
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, "/~") {
|
} else if strings.HasPrefix(rest, "/~") {
|
||||||
host = wshrpc.LocalConnName
|
host = wshrpc.LocalConnName
|
||||||
remotePath = rest
|
remotePath = rest
|
||||||
@ -117,19 +136,10 @@ func ParseURI(uri string) (*Connection, error) {
|
|||||||
host = ConnHostCurrent
|
host = ConnHostCurrent
|
||||||
remotePath = rest
|
remotePath = rest
|
||||||
}
|
}
|
||||||
|
} else if scheme == ConnectionTypeWsh {
|
||||||
|
parseWshPath()
|
||||||
} else {
|
} else {
|
||||||
if strings.HasPrefix(rest, "wsl://") {
|
parseGenericPath()
|
||||||
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 = "/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if scheme == ConnectionTypeWsh {
|
if scheme == ConnectionTypeWsh {
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
|
|
||||||
func FixPath(path string) (string, error) {
|
func FixPath(path string) (string, error) {
|
||||||
if strings.HasPrefix(path, "~") {
|
if strings.HasPrefix(path, "~") {
|
||||||
return filepath.Join(wavebase.GetHomeDir(), path[1:]), nil
|
path = filepath.Join(wavebase.GetHomeDir(), path[1:])
|
||||||
} else if !filepath.IsAbs(path) {
|
} else if !filepath.IsAbs(path) {
|
||||||
log.Printf("FixPath: path is not absolute: %s", path)
|
log.Printf("FixPath: path is not absolute: %s", path)
|
||||||
path, err := filepath.Abs(path)
|
path, err := filepath.Abs(path)
|
||||||
@ -27,10 +27,8 @@ func FixPath(path string) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
log.Printf("FixPath: fixed path: %s", path)
|
log.Printf("FixPath: fixed path: %s", path)
|
||||||
return path, nil
|
|
||||||
} else {
|
|
||||||
return path, nil
|
|
||||||
}
|
}
|
||||||
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
Reference in New Issue
Block a user