Skip to content

Commit 40674e3

Browse files
Copilotsawka
andcommitted
Add RemoteFileMultiInfoCommand RPC and remote implementation
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
1 parent 96db7b8 commit 40674e3

6 files changed

Lines changed: 95 additions & 0 deletions

File tree

frontend/app/store/wshclientapi.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@ class RpcApiType {
572572
return client.wshRpcCall("remotefilemove", data, opts);
573573
}
574574

575+
// command "remotefilemultiinfo" [call]
576+
RemoteFileMultiInfoCommand(client: WshClient, data: CommandRemoteFileMultiInfoData, opts?: RpcOpts): Promise<{[key: string]: FileInfo}> {
577+
return client.wshRpcCall("remotefilemultiinfo", data, opts);
578+
}
579+
575580
// command "remotefiletouch" [call]
576581
RemoteFileTouchCommand(client: WshClient, data: string, opts?: RpcOpts): Promise<void> {
577582
return client.wshRpcCall("remotefiletouch", data, opts);

frontend/types/gotypes.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ declare global {
477477
jobid: string;
478478
};
479479

480+
// wshrpc.CommandRemoteFileMultiInfoData
481+
type CommandRemoteFileMultiInfoData = {
482+
cwd: string;
483+
paths: string[];
484+
};
485+
480486
// wshrpc.CommandRemoteListEntriesData
481487
type CommandRemoteListEntriesData = {
482488
path: string;

pkg/wshrpc/wshclient/wshclient.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,12 @@ func RemoteFileMoveCommand(w *wshutil.WshRpc, data wshrpc.CommandFileCopyData, o
692692
return err
693693
}
694694

695+
// command "remotefilemultiinfo", wshserver.RemoteFileMultiInfoCommand
696+
func RemoteFileMultiInfoCommand(w *wshutil.WshRpc, data wshrpc.CommandRemoteFileMultiInfoData, opts *wshrpc.RpcOpts) (map[string]wshrpc.FileInfo, error) {
697+
resp, err := sendRpcRequestCallHelper[map[string]wshrpc.FileInfo](w, "remotefilemultiinfo", data, opts)
698+
return resp, err
699+
}
700+
695701
// command "remotefiletouch", wshserver.RemoteFileTouchCommand
696702
func RemoteFileTouchCommand(w *wshutil.WshRpc, data string, opts *wshrpc.RpcOpts) error {
697703
_, err := sendRpcRequestCallHelper[any](w, "remotefiletouch", data, opts)

pkg/wshrpc/wshremote/wshremote_file.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,27 @@ func (impl *ServerImpl) RemoteFileInfoCommand(ctx context.Context, path string)
516516
return impl.fileInfoInternal(path, true)
517517
}
518518

519+
func (impl *ServerImpl) RemoteFileMultiInfoCommand(ctx context.Context, data wshrpc.CommandRemoteFileMultiInfoData) (map[string]wshrpc.FileInfo, error) {
520+
cwd := data.Cwd
521+
if cwd == "" {
522+
cwd = "~"
523+
}
524+
cwd = filepath.Clean(wavebase.ExpandHomeDirSafe(cwd))
525+
rtn := make(map[string]wshrpc.FileInfo, len(data.Paths))
526+
for _, path := range data.Paths {
527+
cleanedPath := wavebase.ExpandHomeDirSafe(path)
528+
if !filepath.IsAbs(cleanedPath) {
529+
cleanedPath = filepath.Join(cwd, cleanedPath)
530+
}
531+
fileInfo, err := impl.fileInfoInternal(cleanedPath, false)
532+
if err != nil {
533+
return nil, err
534+
}
535+
rtn[path] = *fileInfo
536+
}
537+
return rtn, nil
538+
}
539+
519540
func (impl *ServerImpl) RemoteFileTouchCommand(ctx context.Context, path string) error {
520541
cleanedPath := filepath.Clean(wavebase.ExpandHomeDirSafe(path))
521542
if _, err := os.Stat(cleanedPath); err == nil {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2026, Command Line Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package wshremote
5+
6+
import (
7+
"context"
8+
"os"
9+
"path/filepath"
10+
"testing"
11+
12+
"github.com/wavetermdev/waveterm/pkg/wshrpc"
13+
)
14+
15+
func TestRemoteFileMultiInfoCommand_PathResolution(t *testing.T) {
16+
homeDir := t.TempDir()
17+
t.Setenv("HOME", homeDir)
18+
19+
cwdDir := filepath.Join(homeDir, "cwd")
20+
if err := os.MkdirAll(cwdDir, 0755); err != nil {
21+
t.Fatalf("mkdir cwd: %v", err)
22+
}
23+
relFile := filepath.Join(cwdDir, "rel.txt")
24+
if err := os.WriteFile(relFile, []byte("rel"), 0644); err != nil {
25+
t.Fatalf("write rel file: %v", err)
26+
}
27+
homeFile := filepath.Join(homeDir, "home.txt")
28+
if err := os.WriteFile(homeFile, []byte("home"), 0644); err != nil {
29+
t.Fatalf("write home file: %v", err)
30+
}
31+
32+
impl := &ServerImpl{}
33+
resp, err := impl.RemoteFileMultiInfoCommand(context.Background(), wshrpc.CommandRemoteFileMultiInfoData{
34+
Cwd: "~/cwd",
35+
Paths: []string{"rel.txt", "~/home.txt", filepath.Join(homeDir, "missing.txt")},
36+
})
37+
if err != nil {
38+
t.Fatalf("RemoteFileMultiInfoCommand returned error: %v", err)
39+
}
40+
41+
if got := resp["rel.txt"].Path; got != "~/cwd/rel.txt" {
42+
t.Fatalf("relative path resolved incorrectly: got %q", got)
43+
}
44+
if got := resp["~/home.txt"].Path; got != "~/home.txt" {
45+
t.Fatalf("home path resolved incorrectly: got %q", got)
46+
}
47+
if !resp[filepath.Join(homeDir, "missing.txt")].NotFound {
48+
t.Fatalf("expected missing path to be marked NotFound")
49+
}
50+
}
51+

pkg/wshrpc/wshrpctypes_file.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type WshRpcRemoteFileInterface interface {
3232
RemoteFileCopyCommand(ctx context.Context, data CommandFileCopyData) (bool, error)
3333
RemoteListEntriesCommand(ctx context.Context, data CommandRemoteListEntriesData) chan RespOrErrorUnion[CommandRemoteListEntriesRtnData]
3434
RemoteFileInfoCommand(ctx context.Context, path string) (*FileInfo, error)
35+
RemoteFileMultiInfoCommand(ctx context.Context, data CommandRemoteFileMultiInfoData) (map[string]FileInfo, error)
3536
RemoteFileTouchCommand(ctx context.Context, path string) error
3637
RemoteFileMoveCommand(ctx context.Context, data CommandFileCopyData) error
3738
RemoteFileDeleteCommand(ctx context.Context, data CommandDeleteFileData) error
@@ -133,6 +134,11 @@ type CommandRemoteListEntriesData struct {
133134
Opts *FileListOpts `json:"opts,omitempty"`
134135
}
135136

137+
type CommandRemoteFileMultiInfoData struct {
138+
Cwd string `json:"cwd"`
139+
Paths []string `json:"paths"`
140+
}
141+
136142
type CommandRemoteListEntriesRtnData struct {
137143
FileInfo []*FileInfo `json:"fileinfo,omitempty"`
138144
}

0 commit comments

Comments
 (0)