Skip to content

Commit 11fec56

Browse files
authored
wsh file overhaul without cross-remote copy and S3 (#1790)
1 parent a5fa098 commit 11fec56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3418
-1202
lines changed

cmd/generatego/main-generatego.go

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func GenerateWshClient() error {
2626
gogen.GenerateBoilerplate(&buf, "wshclient", []string{
2727
"github.com/wavetermdev/waveterm/pkg/wshutil",
2828
"github.com/wavetermdev/waveterm/pkg/wshrpc",
29+
"github.com/wavetermdev/waveterm/pkg/wconfig",
2930
"github.com/wavetermdev/waveterm/pkg/waveobj",
3031
"github.com/wavetermdev/waveterm/pkg/wps",
3132
"github.com/wavetermdev/waveterm/pkg/vdom",

cmd/server/main-server.go

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/wavetermdev/waveterm/pkg/filestore"
2222
"github.com/wavetermdev/waveterm/pkg/panichandler"
2323
"github.com/wavetermdev/waveterm/pkg/remote/conncontroller"
24+
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/wshfs"
2425
"github.com/wavetermdev/waveterm/pkg/service"
2526
"github.com/wavetermdev/waveterm/pkg/telemetry"
2627
"github.com/wavetermdev/waveterm/pkg/util/shellutil"
@@ -175,6 +176,7 @@ func shutdownActivityUpdate() {
175176

176177
func createMainWshClient() {
177178
rpc := wshserver.GetMainRpcClient()
179+
wshfs.RpcClient = rpc
178180
wshutil.DefaultRouter.RegisterRoute(wshutil.DefaultRoute, rpc, true)
179181
wps.Broker.SetClient(wshutil.DefaultRouter)
180182
localConnWsh := wshutil.MakeWshRpc(nil, nil, wshrpc.RpcContext{Conn: wshrpc.LocalConnName}, &wshremote.ServerImpl{})

cmd/wsh/cmd/wshcmd-connserver.go

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/spf13/cobra"
2020
"github.com/wavetermdev/waveterm/pkg/panichandler"
21+
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/wshfs"
2122
"github.com/wavetermdev/waveterm/pkg/util/packetparser"
2223
"github.com/wavetermdev/waveterm/pkg/wavebase"
2324
"github.com/wavetermdev/waveterm/pkg/wshrpc"
@@ -180,6 +181,7 @@ func serverRunRouter(jwtToken string) error {
180181
if err != nil {
181182
return fmt.Errorf("error setting up connserver rpc client: %v", err)
182183
}
184+
wshfs.RpcClient = client
183185
go runListener(unixListener, router)
184186
// run the sysinfo loop
185187
wshremote.RunSysInfoLoop(client, client.GetRpcContext().Conn)
@@ -224,6 +226,7 @@ func serverRunNormal(jwtToken string) error {
224226
if err != nil {
225227
return err
226228
}
229+
wshfs.RpcClient = RpcClient
227230
WriteStdout("running wsh connserver (%s)\n", RpcContext.Conn)
228231
go wshremote.RunSysInfoLoop(RpcClient, RpcContext.Conn)
229232
select {} // run forever

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

+43-24
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
"io/fs"
1111
"strings"
1212

13+
"github.com/wavetermdev/waveterm/pkg/remote/connparse"
14+
"github.com/wavetermdev/waveterm/pkg/util/fileutil"
15+
"github.com/wavetermdev/waveterm/pkg/util/wavefileutil"
1316
"github.com/wavetermdev/waveterm/pkg/wshrpc"
1417
"github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
1518
)
@@ -24,15 +27,11 @@ func convertNotFoundErr(err error) error {
2427
return err
2528
}
2629

27-
func ensureWaveFile(origName string, fileData wshrpc.CommandFileData) (*wshrpc.WaveFileInfo, error) {
30+
func ensureFile(origName string, fileData wshrpc.FileData) (*wshrpc.FileInfo, error) {
2831
info, err := wshclient.FileInfoCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: DefaultFileTimeout})
2932
err = convertNotFoundErr(err)
3033
if err == fs.ErrNotExist {
31-
createData := wshrpc.CommandFileCreateData{
32-
ZoneId: fileData.ZoneId,
33-
FileName: fileData.FileName,
34-
}
35-
err = wshclient.FileCreateCommand(RpcClient, createData, &wshrpc.RpcOpts{Timeout: DefaultFileTimeout})
34+
err = wshclient.FileCreateCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: DefaultFileTimeout})
3635
if err != nil {
3736
return nil, fmt.Errorf("creating file: %w", err)
3837
}
@@ -48,7 +47,7 @@ func ensureWaveFile(origName string, fileData wshrpc.CommandFileData) (*wshrpc.W
4847
return info, nil
4948
}
5049

51-
func streamWriteToWaveFile(fileData wshrpc.CommandFileData, reader io.Reader) error {
50+
func streamWriteToFile(fileData wshrpc.FileData, reader io.Reader) error {
5251
// First truncate the file with an empty write
5352
emptyWrite := fileData
5453
emptyWrite.Data64 = ""
@@ -81,7 +80,7 @@ func streamWriteToWaveFile(fileData wshrpc.CommandFileData, reader io.Reader) er
8180
appendData := fileData
8281
appendData.Data64 = base64.StdEncoding.EncodeToString(chunk)
8382

84-
err = wshclient.FileAppendCommand(RpcClient, appendData, &wshrpc.RpcOpts{Timeout: fileTimeout})
83+
err = wshclient.FileAppendCommand(RpcClient, appendData, &wshrpc.RpcOpts{Timeout: int64(fileTimeout)})
8584
if err != nil {
8685
return fmt.Errorf("appending chunk to file: %w", err)
8786
}
@@ -90,7 +89,7 @@ func streamWriteToWaveFile(fileData wshrpc.CommandFileData, reader io.Reader) er
9089
return nil
9190
}
9291

93-
func streamReadFromWaveFile(fileData wshrpc.CommandFileData, size int64, writer io.Writer) error {
92+
func streamReadFromFile(fileData wshrpc.FileData, size int64, writer io.Writer) error {
9493
const chunkSize = 32 * 1024 // 32KB chunks
9594
for offset := int64(0); offset < size; offset += chunkSize {
9695
// Calculate the length of this chunk
@@ -100,19 +99,19 @@ func streamReadFromWaveFile(fileData wshrpc.CommandFileData, size int64, writer
10099
}
101100

102101
// Set up the ReadAt request
103-
fileData.At = &wshrpc.CommandFileDataAt{
102+
fileData.At = &wshrpc.FileDataAt{
104103
Offset: offset,
105-
Size: int64(length),
104+
Size: length,
106105
}
107106

108107
// Read the chunk
109-
content64, err := wshclient.FileReadCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})
108+
data, err := wshclient.FileReadCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: int64(fileTimeout)})
110109
if err != nil {
111110
return fmt.Errorf("reading chunk at offset %d: %w", offset, err)
112111
}
113112

114113
// Decode and write the chunk
115-
chunk, err := base64.StdEncoding.DecodeString(content64)
114+
chunk, err := base64.StdEncoding.DecodeString(data.Data64)
116115
if err != nil {
117116
return fmt.Errorf("decoding chunk at offset %d: %w", offset, err)
118117
}
@@ -127,7 +126,7 @@ func streamReadFromWaveFile(fileData wshrpc.CommandFileData, size int64, writer
127126
}
128127

129128
type fileListResult struct {
130-
info *wshrpc.WaveFileInfo
129+
info *wshrpc.FileInfo
131130
err error
132131
}
133132

@@ -139,9 +138,9 @@ func streamFileList(zoneId string, path string, recursive bool, filesOnly bool)
139138
go func() {
140139
defer close(resultChan)
141140

142-
fileData := wshrpc.CommandFileData{
143-
ZoneId: zoneId,
144-
FileName: path,
141+
fileData := wshrpc.FileData{
142+
Info: &wshrpc.FileInfo{
143+
Path: fmt.Sprintf(wavefileutil.WaveFilePathPattern, zoneId, path)},
145144
}
146145

147146
info, err := wshclient.FileInfoCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: 2000})
@@ -169,13 +168,12 @@ func streamFileList(zoneId string, path string, recursive bool, filesOnly bool)
169168
foundAny := false
170169

171170
for {
172-
listData := wshrpc.CommandFileListData{
173-
ZoneId: zoneId,
174-
Prefix: prefix,
175-
All: recursive,
176-
Offset: offset,
177-
Limit: 100,
178-
}
171+
listData := wshrpc.FileListData{
172+
Path: fmt.Sprintf(wavefileutil.WaveFilePathPattern, zoneId, prefix),
173+
Opts: &wshrpc.FileListOpts{
174+
All: recursive,
175+
Offset: offset,
176+
Limit: 100}}
179177

180178
files, err := wshclient.FileListCommand(RpcClient, listData, &wshrpc.RpcOpts{Timeout: 2000})
181179
if err != nil {
@@ -210,3 +208,24 @@ func streamFileList(zoneId string, path string, recursive bool, filesOnly bool)
210208

211209
return resultChan, nil
212210
}
211+
212+
func fixRelativePaths(path string) (string, error) {
213+
conn, err := connparse.ParseURI(path)
214+
if err != nil {
215+
return "", err
216+
}
217+
if conn.Scheme == connparse.ConnectionTypeWsh {
218+
if conn.Host == connparse.ConnHostCurrent {
219+
conn.Host = RpcContext.Conn
220+
fixedPath, err := fileutil.FixPath(conn.Path)
221+
if err != nil {
222+
return "", err
223+
}
224+
conn.Path = fixedPath
225+
}
226+
if conn.Host == "" {
227+
conn.Host = wshrpc.LocalConnName
228+
}
229+
}
230+
return conn.GetFullURI(), nil
231+
}

0 commit comments

Comments
 (0)