Skip to content

Commit fb48669

Browse files
committed
switch file cat to use new modern streaming, remove file limit
1 parent a6062c2 commit fb48669

3 files changed

Lines changed: 43 additions & 11 deletions

File tree

cmd/wsh/cmd/wshcmd-file-util.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025, Command Line Inc.
1+
// Copyright 2026, Command Line Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

44
package cmd
@@ -12,10 +12,10 @@ import (
1212
"strings"
1313

1414
"github.com/wavetermdev/waveterm/pkg/remote/connparse"
15-
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/fsutil"
1615
"github.com/wavetermdev/waveterm/pkg/util/fileutil"
1716
"github.com/wavetermdev/waveterm/pkg/wshrpc"
1817
"github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
18+
"github.com/wavetermdev/waveterm/pkg/wshutil"
1919
)
2020

2121
func convertNotFoundErr(err error) error {
@@ -91,8 +91,38 @@ func streamWriteToFile(fileData wshrpc.FileData, reader io.Reader) error {
9191
}
9292

9393
func streamReadFromFile(ctx context.Context, fileData wshrpc.FileData, writer io.Writer) error {
94-
ch := wshclient.FileReadStreamCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})
95-
return fsutil.ReadFileStreamToWriter(ctx, ch, writer)
94+
broker := RpcClient.StreamBroker
95+
if broker == nil {
96+
return fmt.Errorf("stream broker not available")
97+
}
98+
if fileData.Info == nil {
99+
return fmt.Errorf("file info is required")
100+
}
101+
readerRouteId := RpcClientRouteId
102+
if readerRouteId == "" {
103+
return fmt.Errorf("no route id available")
104+
}
105+
conn, err := connparse.ParseURI(fileData.Info.Path)
106+
if err != nil {
107+
return fmt.Errorf("parsing file path: %w", err)
108+
}
109+
writerRouteId := wshutil.MakeConnectionRouteId(conn.Host)
110+
reader, streamMeta := broker.CreateStreamReader(readerRouteId, writerRouteId, 256*1024)
111+
defer reader.Close()
112+
go func() {
113+
<-ctx.Done()
114+
reader.Close()
115+
}()
116+
data := wshrpc.CommandFileStreamData{
117+
Info: fileData.Info,
118+
StreamMeta: *streamMeta,
119+
}
120+
_, err = wshclient.FileStreamCommand(RpcClient, data, nil)
121+
if err != nil {
122+
return fmt.Errorf("starting file stream: %w", err)
123+
}
124+
_, err = io.Copy(writer, reader)
125+
return err
96126
}
97127

98128
func fixRelativePaths(path string) (string, error) {

cmd/wsh/cmd/wshcmd-file.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,6 @@ func fileCatRun(cmd *cobra.Command, args []string) error {
172172
return err
173173
}
174174

175-
_, err = checkFileSize(path, MaxFileSize)
176-
if err != nil {
177-
return err
178-
}
179-
180175
fileData := wshrpc.FileData{
181176
Info: &wshrpc.FileInfo{
182177
Path: path}}

cmd/wsh/cmd/wshcmd-root.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var WrappedStdout io.Writer = &WrappedWriter{dest: os.Stdout}
3131
var WrappedStderr io.Writer = &WrappedWriter{dest: os.Stderr}
3232
var RpcClient *wshutil.WshRpc
3333
var RpcContext wshrpc.RpcContext
34+
var RpcClientRouteId string
3435
var UsingTermWshMode bool
3536
var blockArg string
3637
var WshExitCode int
@@ -140,7 +141,12 @@ func setupRpcClientWithToken(swapTokenStr string) (wshrpc.CommandAuthenticateRtn
140141
if err != nil {
141142
return rtn, fmt.Errorf("error setting up domain socket rpc client: %w", err)
142143
}
143-
return wshclient.AuthenticateTokenCommand(RpcClient, wshrpc.CommandAuthenticateTokenData{Token: token.Token}, &wshrpc.RpcOpts{Route: wshutil.ControlRoute})
144+
rtn, err = wshclient.AuthenticateTokenCommand(RpcClient, wshrpc.CommandAuthenticateTokenData{Token: token.Token}, &wshrpc.RpcOpts{Route: wshutil.ControlRoute})
145+
if err != nil {
146+
return rtn, err
147+
}
148+
RpcClientRouteId = rtn.RouteId
149+
return rtn, nil
144150
}
145151

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

0 commit comments

Comments
 (0)