Fix windows path for wsh url (#1798)

This commit is contained in:
Evan Simkowitz 2025-01-22 17:28:59 -08:00 committed by GitHub
parent 62eec93b17
commit a98242138d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 16 deletions

View File

@ -324,7 +324,7 @@ func TestWriteAt(t *testing.T) {
defer cancelFn()
fileName := "t3"
zoneId := uuid.NewString()
err := WFS.MakeFile(ctx, zoneId, fileName, nil, FileOptsType{})
err := WFS.MakeFile(ctx, zoneId, fileName, nil, wshrpc.FileOpts{})
if err != nil {
t.Fatalf("error creating file: %v", err)
}

View File

@ -6,6 +6,7 @@ package connparse
import (
"context"
"fmt"
"regexp"
"strings"
"github.com/wavetermdev/waveterm/pkg/wshrpc"
@ -21,6 +22,8 @@ const (
ConnHostWaveSrv = "wavesrv"
)
var windowsDriveRegex = regexp.MustCompile(`^[a-zA-Z]:`)
type Connection struct {
Scheme string
Host string
@ -100,11 +103,10 @@ func ParseURI(uri string) (*Connection, error) {
if strings.HasPrefix(rest, "//") {
rest = strings.TrimPrefix(rest, "//")
split = strings.SplitN(rest, "/", 2)
host = split[0]
if len(split) > 1 {
host = split[0]
remotePath = "/" + split[1]
remotePath = split[1]
} else {
host = split[0]
remotePath = "/"
}
} else if strings.HasPrefix(rest, "/~") {
@ -116,11 +118,10 @@ func ParseURI(uri string) (*Connection, error) {
}
} else {
split = strings.SplitN(rest, "/", 2)
host = split[0]
if len(split) > 1 {
host = split[0]
remotePath = "/" + split[1]
remotePath = split[1]
} else {
host = split[0]
remotePath = "/"
}
}
@ -131,6 +132,8 @@ func ParseURI(uri string) (*Connection, error) {
}
if strings.HasPrefix(remotePath, "/~") {
remotePath = strings.TrimPrefix(remotePath, "/")
} else if len(remotePath) > 1 && !windowsDriveRegex.MatchString(remotePath) && !strings.HasPrefix(remotePath, "/") {
remotePath = "/" + remotePath
}
}

View File

@ -162,25 +162,21 @@ func (impl *ServerImpl) remoteStreamFileInternal(ctx context.Context, data wshrp
if err != nil {
return err
}
path, err := wavebase.ExpandHomeDir(data.Path)
finfo, err := impl.fileInfoInternal(data.Path, true)
if err != nil {
return err
}
finfo, err := impl.fileInfoInternal(path, true)
if err != nil {
return fmt.Errorf("cannot stat file %q: %w", path, err)
return fmt.Errorf("cannot stat file %q: %w", data.Path, err)
}
dataCallback([]*wshrpc.FileInfo{finfo}, nil, byteRange)
if finfo.NotFound {
return nil
}
if finfo.Size > wshrpc.MaxFileSize {
return fmt.Errorf("file %q is too large to read, use /wave/stream-file", path)
return fmt.Errorf("file %q is too large to read, use /wave/stream-file", finfo.Path)
}
if finfo.IsDir {
return impl.remoteStreamFileDir(ctx, path, byteRange, dataCallback)
return impl.remoteStreamFileDir(ctx, finfo.Path, byteRange, dataCallback)
} else {
return impl.remoteStreamFileRegular(ctx, path, byteRange, dataCallback)
return impl.remoteStreamFileRegular(ctx, finfo.Path, byteRange, dataCallback)
}
}