@@ -10,6 +10,9 @@ import (
10
10
"io/fs"
11
11
"strings"
12
12
13
+ "github.com/wavetermdev/waveterm/pkg/remote/connparse"
14
+ "github.com/wavetermdev/waveterm/pkg/util/fileutil"
15
+ "github.com/wavetermdev/waveterm/pkg/util/wavefileutil"
13
16
"github.com/wavetermdev/waveterm/pkg/wshrpc"
14
17
"github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
15
18
)
@@ -24,15 +27,11 @@ func convertNotFoundErr(err error) error {
24
27
return err
25
28
}
26
29
27
- func ensureWaveFile (origName string , fileData wshrpc.CommandFileData ) (* wshrpc.WaveFileInfo , error ) {
30
+ func ensureFile (origName string , fileData wshrpc.FileData ) (* wshrpc.FileInfo , error ) {
28
31
info , err := wshclient .FileInfoCommand (RpcClient , fileData , & wshrpc.RpcOpts {Timeout : DefaultFileTimeout })
29
32
err = convertNotFoundErr (err )
30
33
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 })
36
35
if err != nil {
37
36
return nil , fmt .Errorf ("creating file: %w" , err )
38
37
}
@@ -48,7 +47,7 @@ func ensureWaveFile(origName string, fileData wshrpc.CommandFileData) (*wshrpc.W
48
47
return info , nil
49
48
}
50
49
51
- func streamWriteToWaveFile (fileData wshrpc.CommandFileData , reader io.Reader ) error {
50
+ func streamWriteToFile (fileData wshrpc.FileData , reader io.Reader ) error {
52
51
// First truncate the file with an empty write
53
52
emptyWrite := fileData
54
53
emptyWrite .Data64 = ""
@@ -81,7 +80,7 @@ func streamWriteToWaveFile(fileData wshrpc.CommandFileData, reader io.Reader) er
81
80
appendData := fileData
82
81
appendData .Data64 = base64 .StdEncoding .EncodeToString (chunk )
83
82
84
- err = wshclient .FileAppendCommand (RpcClient , appendData , & wshrpc.RpcOpts {Timeout : fileTimeout })
83
+ err = wshclient .FileAppendCommand (RpcClient , appendData , & wshrpc.RpcOpts {Timeout : int64 ( fileTimeout ) })
85
84
if err != nil {
86
85
return fmt .Errorf ("appending chunk to file: %w" , err )
87
86
}
@@ -90,7 +89,7 @@ func streamWriteToWaveFile(fileData wshrpc.CommandFileData, reader io.Reader) er
90
89
return nil
91
90
}
92
91
93
- func streamReadFromWaveFile (fileData wshrpc.CommandFileData , size int64 , writer io.Writer ) error {
92
+ func streamReadFromFile (fileData wshrpc.FileData , size int64 , writer io.Writer ) error {
94
93
const chunkSize = 32 * 1024 // 32KB chunks
95
94
for offset := int64 (0 ); offset < size ; offset += chunkSize {
96
95
// Calculate the length of this chunk
@@ -100,19 +99,19 @@ func streamReadFromWaveFile(fileData wshrpc.CommandFileData, size int64, writer
100
99
}
101
100
102
101
// Set up the ReadAt request
103
- fileData .At = & wshrpc.CommandFileDataAt {
102
+ fileData .At = & wshrpc.FileDataAt {
104
103
Offset : offset ,
105
- Size : int64 ( length ) ,
104
+ Size : length ,
106
105
}
107
106
108
107
// 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 ) })
110
109
if err != nil {
111
110
return fmt .Errorf ("reading chunk at offset %d: %w" , offset , err )
112
111
}
113
112
114
113
// Decode and write the chunk
115
- chunk , err := base64 .StdEncoding .DecodeString (content64 )
114
+ chunk , err := base64 .StdEncoding .DecodeString (data . Data64 )
116
115
if err != nil {
117
116
return fmt .Errorf ("decoding chunk at offset %d: %w" , offset , err )
118
117
}
@@ -127,7 +126,7 @@ func streamReadFromWaveFile(fileData wshrpc.CommandFileData, size int64, writer
127
126
}
128
127
129
128
type fileListResult struct {
130
- info * wshrpc.WaveFileInfo
129
+ info * wshrpc.FileInfo
131
130
err error
132
131
}
133
132
@@ -139,9 +138,9 @@ func streamFileList(zoneId string, path string, recursive bool, filesOnly bool)
139
138
go func () {
140
139
defer close (resultChan )
141
140
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 )} ,
145
144
}
146
145
147
146
info , err := wshclient .FileInfoCommand (RpcClient , fileData , & wshrpc.RpcOpts {Timeout : 2000 })
@@ -169,13 +168,12 @@ func streamFileList(zoneId string, path string, recursive bool, filesOnly bool)
169
168
foundAny := false
170
169
171
170
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 }}
179
177
180
178
files , err := wshclient .FileListCommand (RpcClient , listData , & wshrpc.RpcOpts {Timeout : 2000 })
181
179
if err != nil {
@@ -210,3 +208,24 @@ func streamFileList(zoneId string, path string, recursive bool, filesOnly bool)
210
208
211
209
return resultChan , nil
212
210
}
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