Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
switch file cat to use new modern streaming, remove file limit
  • Loading branch information
sawka committed Mar 20, 2026
commit fb48669abf11525e09fa78945438c909edb1ce06
38 changes: 34 additions & 4 deletions cmd/wsh/cmd/wshcmd-file-util.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025, Command Line Inc.
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

package cmd
Expand All @@ -12,10 +12,10 @@ import (
"strings"

"github.com/wavetermdev/waveterm/pkg/remote/connparse"
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/fsutil"
"github.com/wavetermdev/waveterm/pkg/util/fileutil"
"github.com/wavetermdev/waveterm/pkg/wshrpc"
"github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
"github.com/wavetermdev/waveterm/pkg/wshutil"
)

func convertNotFoundErr(err error) error {
Expand Down Expand Up @@ -91,8 +91,38 @@ func streamWriteToFile(fileData wshrpc.FileData, reader io.Reader) error {
}

func streamReadFromFile(ctx context.Context, fileData wshrpc.FileData, writer io.Writer) error {
ch := wshclient.FileReadStreamCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})
return fsutil.ReadFileStreamToWriter(ctx, ch, writer)
broker := RpcClient.StreamBroker
if broker == nil {
return fmt.Errorf("stream broker not available")
}
if fileData.Info == nil {
return fmt.Errorf("file info is required")
}
readerRouteId := RpcClientRouteId
if readerRouteId == "" {
return fmt.Errorf("no route id available")
}
conn, err := connparse.ParseURI(fileData.Info.Path)
if err != nil {
return fmt.Errorf("parsing file path: %w", err)
}
writerRouteId := wshutil.MakeConnectionRouteId(conn.Host)
reader, streamMeta := broker.CreateStreamReader(readerRouteId, writerRouteId, 256*1024)
defer reader.Close()
go func() {
<-ctx.Done()
reader.Close()
}()
data := wshrpc.CommandFileStreamData{
Info: fileData.Info,
StreamMeta: *streamMeta,
}
_, err = wshclient.FileStreamCommand(RpcClient, data, nil)
if err != nil {
return fmt.Errorf("starting file stream: %w", err)
}
_, err = io.Copy(writer, reader)
return err
}

func fixRelativePaths(path string) (string, error) {
Expand Down
5 changes: 0 additions & 5 deletions cmd/wsh/cmd/wshcmd-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,6 @@ func fileCatRun(cmd *cobra.Command, args []string) error {
return err
}

_, err = checkFileSize(path, MaxFileSize)
if err != nil {
return err
}

fileData := wshrpc.FileData{
Info: &wshrpc.FileInfo{
Path: path}}
Expand Down
11 changes: 9 additions & 2 deletions cmd/wsh/cmd/wshcmd-root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var WrappedStdout io.Writer = &WrappedWriter{dest: os.Stdout}
var WrappedStderr io.Writer = &WrappedWriter{dest: os.Stderr}
var RpcClient *wshutil.WshRpc
var RpcContext wshrpc.RpcContext
var RpcClientRouteId string
var UsingTermWshMode bool
var blockArg string
var WshExitCode int
Expand Down Expand Up @@ -140,7 +141,12 @@ func setupRpcClientWithToken(swapTokenStr string) (wshrpc.CommandAuthenticateRtn
if err != nil {
return rtn, fmt.Errorf("error setting up domain socket rpc client: %w", err)
}
return wshclient.AuthenticateTokenCommand(RpcClient, wshrpc.CommandAuthenticateTokenData{Token: token.Token}, &wshrpc.RpcOpts{Route: wshutil.ControlRoute})
rtn, err = wshclient.AuthenticateTokenCommand(RpcClient, wshrpc.CommandAuthenticateTokenData{Token: token.Token}, &wshrpc.RpcOpts{Route: wshutil.ControlRoute})
if err != nil {
return rtn, err
}
RpcClientRouteId = rtn.RouteId
return rtn, nil
}

// returns the wrapped stdin and a new rpc client (that wraps the stdin input and stdout output)
Expand All @@ -158,10 +164,11 @@ func setupRpcClient(serverImpl wshutil.ServerImpl, jwtToken string) error {
if err != nil {
return fmt.Errorf("error setting up domain socket rpc client: %v", err)
}
_, err = wshclient.AuthenticateCommand(RpcClient, jwtToken, &wshrpc.RpcOpts{Route: wshutil.ControlRoute})
authRtn, err := wshclient.AuthenticateCommand(RpcClient, jwtToken, &wshrpc.RpcOpts{Route: wshutil.ControlRoute})
if err != nil {
return fmt.Errorf("error authenticating: %v", err)
}
RpcClientRouteId = authRtn.RouteId
blockId := os.Getenv("WAVETERM_BLOCKID")
if blockId != "" {
peerInfo := fmt.Sprintf("domain:block:%s", blockId)
Expand Down