Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable wsh file cross-remote copy/move #1725

Merged
merged 155 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 146 commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
4c219ee
initial commit
esimkowitz Jan 3, 2025
1003187
save
esimkowitz Jan 3, 2025
f652ad0
Merge branch 'main' into evan/remote-s3
esimkowitz Jan 6, 2025
39aae45
save
esimkowitz Jan 6, 2025
4d20ebb
use fsclient in fileservice
esimkowitz Jan 7, 2025
7b9fc52
remove listentries
esimkowitz Jan 7, 2025
ac8a08b
fix name
esimkowitz Jan 7, 2025
6a34b0b
save
esimkowitz Jan 7, 2025
721653e
Merge branch 'main' into evan/remote-s3
esimkowitz Jan 7, 2025
acebeaa
add parseprofiles
esimkowitz Jan 8, 2025
58be97d
add connparse
esimkowitz Jan 8, 2025
cffd151
Merge branch 'main' into evan/remote-s3
esimkowitz Jan 8, 2025
5596aa7
switch import order
esimkowitz Jan 8, 2025
a6581d4
add boilerplate wavefs impl
esimkowitz Jan 8, 2025
9f23437
Merge branch 'main' into evan/remote-s3
esimkowitz Jan 10, 2025
dfc0ea3
save
esimkowitz Jan 11, 2025
ccdcf4e
connparse impl
esimkowitz Jan 13, 2025
d59497a
add back parseprofiles, make more modular
esimkowitz Jan 13, 2025
1191597
generate
esimkowitz Jan 13, 2025
1d2f1fe
save
esimkowitz Jan 13, 2025
3dd5070
save
esimkowitz Jan 14, 2025
0753a7b
got listentries implemented
esimkowitz Jan 14, 2025
d491ffa
save
esimkowitz Jan 14, 2025
d7f3a18
comment
esimkowitz Jan 14, 2025
6219bb7
add supportsmkdir
esimkowitz Jan 14, 2025
6414fba
move getfullconfig to wshrpc
esimkowitz Jan 14, 2025
cf77583
fix wsh errors
esimkowitz Jan 14, 2025
1deeb16
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 14, 2025
4022182
more plumbing
esimkowitz Jan 14, 2025
098730c
save
esimkowitz Jan 15, 2025
8f863db
fixed conn issue
esimkowitz Jan 15, 2025
9de524f
cat is working!
esimkowitz Jan 15, 2025
96e6725
formatting info
esimkowitz Jan 15, 2025
57deb43
add updated help text
esimkowitz Jan 15, 2025
041720a
update text
esimkowitz Jan 15, 2025
1ad2372
update text
esimkowitz Jan 15, 2025
294ae81
update text
esimkowitz Jan 15, 2025
e265cca
fix indents
esimkowitz Jan 15, 2025
75b5bf7
remove newline
esimkowitz Jan 15, 2025
aca09f2
more formatting
esimkowitz Jan 15, 2025
ca281d6
more improvements
esimkowitz Jan 15, 2025
579a6e8
fix wavefile scheme
esimkowitz Jan 15, 2025
fba2550
move wavefile below others
esimkowitz Jan 15, 2025
3bb25cb
more doc updates
esimkowitz Jan 15, 2025
58785c8
got ls working
esimkowitz Jan 15, 2025
489c81e
add default . to ls
esimkowitz Jan 15, 2025
106d9c7
move fixRelativePaths to wshcmd-file-util
esimkowitz Jan 15, 2025
44f48d6
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 15, 2025
281220a
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 15, 2025
778337c
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 15, 2025
66e2461
it's working!!!!
esimkowitz Jan 15, 2025
b2b16ed
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 15, 2025
1410f31
add readstream
esimkowitz Jan 16, 2025
f71a04f
save
esimkowitz Jan 16, 2025
1a2c6b0
got ui working
esimkowitz Jan 16, 2025
65b50bd
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 16, 2025
2e00cac
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 16, 2025
714c60d
fix merge error
esimkowitz Jan 16, 2025
149126a
update comment
esimkowitz Jan 16, 2025
2c525b8
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 16, 2025
47df22f
add tar stream command
esimkowitz Jan 16, 2025
81c7b47
add iochan test
esimkowitz Jan 16, 2025
2311577
tar seems to be working, can't write files to os
esimkowitz Jan 17, 2025
d992edc
save work
esimkowitz Jan 17, 2025
43a3f29
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 17, 2025
3b3b167
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 17, 2025
09f4239
fix merge error
esimkowitz Jan 17, 2025
d7e65a4
save
esimkowitz Jan 17, 2025
91c6525
add listbuckets
esimkowitz Jan 17, 2025
280e454
move listbuckets to awsconn
esimkowitz Jan 17, 2025
bc76164
save
esimkowitz Jan 17, 2025
29419fa
it works! timing out but still
esimkowitz Jan 18, 2025
e44ea1c
working, getting copy file error read/write on closed pipe, need to i…
esimkowitz Jan 18, 2025
fa94263
don't allow unregister to block the main sending loop
sawka Jan 18, 2025
d707995
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 21, 2025
1fe895f
it's working!
esimkowitz Jan 21, 2025
5f42b97
save
esimkowitz Jan 21, 2025
c0e25d6
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 21, 2025
367044e
add panichandler to runServer
sawka Jan 21, 2025
570885b
timeout
esimkowitz Jan 21, 2025
c76ca37
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 21, 2025
3283314
Disable S3, add fileappend
esimkowitz Jan 21, 2025
e043a7b
clean up opts, fix append for wavefile
esimkowitz Jan 22, 2025
0fb579c
fix race condition around ctx.Done() and unregisterRpc() that can hap…
sawka Jan 22, 2025
d37e7de
update filestore to use ints for size
esimkowitz Jan 22, 2025
91e80b3
Potential fix for code scanning alert no. 72: Arbitrary file access d…
esimkowitz Jan 22, 2025
d9c1013
Update pkg/remote/awsconn/awsconn.go
esimkowitz Jan 22, 2025
20e393c
Update pkg/remote/awsconn/awsconn.go
esimkowitz Jan 22, 2025
74e8f60
Update pkg/remote/awsconn/awsconn.go
esimkowitz Jan 22, 2025
8541f72
Update pkg/util/iochan/iochan.go
esimkowitz Jan 22, 2025
d7e8b47
Update pkg/util/iochan/iochan.go
esimkowitz Jan 22, 2025
9355950
Update pkg/remote/fileshare/s3fs/s3fs.go
esimkowitz Jan 22, 2025
27d26c2
Update pkg/wshrpc/wshrpctypes.go
esimkowitz Jan 22, 2025
d38c3aa
use time.Duration for timeouts
esimkowitz Jan 22, 2025
3a31a0e
Update pkg/remote/fileshare/wavefs/wavefs.go
esimkowitz Jan 22, 2025
a940146
fix readstream for loops
esimkowitz Jan 22, 2025
a682ed6
revert changes from rpc pr
esimkowitz Jan 22, 2025
a429c6f
save
esimkowitz Jan 22, 2025
92dac0a
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 22, 2025
0da6d14
fix merge errors
esimkowitz Jan 23, 2025
f4077e0
fix merge errors
esimkowitz Jan 23, 2025
532060c
more merge errors
esimkowitz Jan 23, 2025
d496aae
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 25, 2025
3b7f165
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 28, 2025
4483554
save
esimkowitz Jan 28, 2025
e9b4209
add cancel handles
esimkowitz Jan 28, 2025
fc5a968
add debugging
esimkowitz Jan 28, 2025
ae650c2
save
esimkowitz Jan 28, 2025
ef772e7
add recursive delete
esimkowitz Jan 28, 2025
8e718cd
fix bug
esimkowitz Jan 28, 2025
966eaab
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 28, 2025
fabf85a
avoid buffer reuse
esimkowitz Jan 28, 2025
5c6feb1
remove artificial delay
esimkowitz Jan 28, 2025
41df9d5
remove annoying logs
esimkowitz Jan 28, 2025
b10cec1
save
esimkowitz Jan 28, 2025
536ffc3
remove file limit for streaming, add timeout
esimkowitz Jan 28, 2025
b1f2175
comment out s3 again
esimkowitz Jan 28, 2025
e3eea07
Add sha sum check to copy
esimkowitz Jan 28, 2025
5b1e0e1
clean up logging
esimkowitz Jan 28, 2025
eb7a68a
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 28, 2025
78e6d32
add remote move impl
esimkowitz Jan 28, 2025
2d83a7f
fix delete in mv
esimkowitz Jan 28, 2025
8ed10f7
route tar stream call to wavesrv, consolidate tar copy to new package…
esimkowitz Jan 29, 2025
52348c4
move dest of copy to tarcopy
esimkowitz Jan 29, 2025
f7351ad
clean filepath in tarcopy
esimkowitz Jan 29, 2025
a8daf52
update error msg
esimkowitz Jan 29, 2025
0b4691a
Update cmd/wsh/cmd/wshcmd-file.go
esimkowitz Jan 29, 2025
d8770a3
handle err in walk
esimkowitz Jan 29, 2025
2db3666
remove unnecessary ctx check
esimkowitz Jan 29, 2025
3485489
Add wavefs tar stream
esimkowitz Jan 29, 2025
0c44c24
add tar stream for wavefile
esimkowitz Jan 29, 2025
f149473
add unsupported errors for s3 impl until ready
esimkowitz Jan 29, 2025
a141d52
add "recursive" delete for wavefs
esimkowitz Jan 29, 2025
a4e6d52
add comments to tarcopy
esimkowitz Jan 29, 2025
722c888
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 29, 2025
ba8bc26
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 29, 2025
9dc8ebf
simplify graceful close logic, add log if fails after n retries
esimkowitz Jan 29, 2025
8a8225a
don't need to cancel the writer context in defer if the pipereader cl…
esimkowitz Jan 29, 2025
8211e82
continue on error for recursive wavefile delete
esimkowitz Jan 29, 2025
fa94e2d
move validate to separate func
esimkowitz Jan 29, 2025
7121868
fix relative paths
esimkowitz Jan 29, 2025
eadc3dd
fix bug not showing errors, bug with prefix when copying single file,…
esimkowitz Jan 29, 2025
73afcc1
fix relative subpaths, improve metrics in logs
esimkowitz Jan 29, 2025
82abf36
Update pkg/util/tarcopy/tarcopy.go
esimkowitz Jan 29, 2025
57feafb
increase default timeout for copy
esimkowitz Jan 29, 2025
3b28f01
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 29, 2025
317dae4
remove fixpath logs
esimkowitz Jan 29, 2025
9265cd0
fix channel leak in wshutil
esimkowitz Jan 29, 2025
95cae0c
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 29, 2025
fb0f0cb
conditionally drain channel in writerchan
esimkowitz Jan 29, 2025
0b9bdd5
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 30, 2025
bba5980
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 31, 2025
449e6cc
Update pkg/wshrpc/wshremote/wshremote.go
esimkowitz Jan 31, 2025
0d7faf9
Update pkg/util/fileutil/fileutil.go
esimkowitz Jan 31, 2025
4749943
Merge branch 'main' into evan/combine-wsh-file-commands
esimkowitz Jan 31, 2025
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
1 change: 1 addition & 0 deletions cmd/generatego/main-generatego.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func GenerateWshClient() error {
"github.com/wavetermdev/waveterm/pkg/waveobj",
"github.com/wavetermdev/waveterm/pkg/wps",
"github.com/wavetermdev/waveterm/pkg/vdom",
"github.com/wavetermdev/waveterm/pkg/util/iochan/iochantypes",
})
wshDeclMap := wshrpc.GenerateWshCommandDeclMap()
for _, key := range utilfn.GetOrderedMapKeys(wshDeclMap) {
Expand Down
7 changes: 6 additions & 1 deletion cmd/wsh/cmd/wshcmd-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func init() {
fileCmd.AddCommand(fileListCmd)
fileCmd.AddCommand(fileCatCmd)
fileCmd.AddCommand(fileWriteCmd)
fileRmCmd.Flags().BoolP("recursive", "r", false, "remove directories recursively")
fileCmd.AddCommand(fileRmCmd)
fileCmd.AddCommand(fileInfoCmd)
fileCmd.AddCommand(fileAppendCmd)
Expand Down Expand Up @@ -259,6 +260,10 @@ func fileRmRun(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
recursive, err := cmd.Flags().GetBool("recursive")
if err != nil {
return err
}
fileData := wshrpc.FileData{
Info: &wshrpc.FileInfo{
Path: path}}
Expand All @@ -272,7 +277,7 @@ func fileRmRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("getting file info: %w", err)
}

err = wshclient.FileDeleteCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: DefaultFileTimeout})
err = wshclient.FileDeleteCommand(RpcClient, wshrpc.CommandDeleteFileData{Path: path, Recursive: recursive}, &wshrpc.RpcOpts{Timeout: DefaultFileTimeout})
if err != nil {
return fmt.Errorf("removing file: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/store/wshclientapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class RpcApiType {
}

// command "filedelete" [call]
FileDeleteCommand(client: WshClient, data: FileData, opts?: RpcOpts): Promise<void> {
FileDeleteCommand(client: WshClient, data: CommandDeleteFileData, opts?: RpcOpts): Promise<void> {
return client.wshRpcCall("filedelete", data, opts);
}

Expand Down Expand Up @@ -203,7 +203,7 @@ class RpcApiType {
}

// command "filestreamtar" [responsestream]
FileStreamTarCommand(client: WshClient, data: CommandRemoteStreamTarData, opts?: RpcOpts): AsyncGenerator<string, void, boolean> {
FileStreamTarCommand(client: WshClient, data: CommandRemoteStreamTarData, opts?: RpcOpts): AsyncGenerator<Packet, void, boolean> {
return client.wshRpcStream("filestreamtar", data, opts);
}

Expand Down Expand Up @@ -258,7 +258,7 @@ class RpcApiType {
}

// command "remotefiledelete" [call]
RemoteFileDeleteCommand(client: WshClient, data: string, opts?: RpcOpts): Promise<void> {
RemoteFileDeleteCommand(client: WshClient, data: CommandDeleteFileData, opts?: RpcOpts): Promise<void> {
return client.wshRpcCall("remotefiledelete", data, opts);
}

Expand Down Expand Up @@ -313,7 +313,7 @@ class RpcApiType {
}

// command "remotetarstream" [responsestream]
RemoteTarStreamCommand(client: WshClient, data: CommandRemoteStreamTarData, opts?: RpcOpts): AsyncGenerator<string, void, boolean> {
RemoteTarStreamCommand(client: WshClient, data: CommandRemoteStreamTarData, opts?: RpcOpts): AsyncGenerator<Packet, void, boolean> {
return client.wshRpcStream("remotetarstream", data, opts);
}

Expand Down
12 changes: 12 additions & 0 deletions frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ declare global {
blockid: string;
};

// wshrpc.CommandDeleteFileData
type CommandDeleteFileData = {
path: string;
recursive: boolean;
};

// wshrpc.CommandDisposeData
type CommandDisposeData = {
routeid: string;
Expand Down Expand Up @@ -583,6 +589,12 @@ declare global {
// waveobj.ORef
type ORef = string;

// iochantypes.Packet
type Packet = {
Data: string;
Checksum: string;
};

// wshrpc.PathCommandData
type PathCommandData = {
pathtype: string;
Expand Down
29 changes: 7 additions & 22 deletions pkg/remote/awsconn/awsconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,13 @@ func ParseProfiles() map[string]struct{} {
}

func ListBuckets(ctx context.Context, client *s3.Client) ([]types.Bucket, error) {
var err error
var output *s3.ListBucketsOutput
var buckets []types.Bucket
region := client.Options().Region
bucketPaginator := s3.NewListBucketsPaginator(client, &s3.ListBucketsInput{BucketRegion: &region})
for bucketPaginator.HasMorePages() {
output, err = bucketPaginator.NextPage(ctx)
log.Printf("output: %v", output)
if err != nil {
var apiErr smithy.APIError
if errors.As(err, &apiErr) && apiErr.ErrorCode() == "AccessDenied" {
fmt.Println("You don't have permission to list buckets for this account.")
err = apiErr
} else {
return nil, fmt.Errorf("Couldn't list buckets for your account. Here's why: %v\n", err)
}
break
}
if output == nil {
break
output, err := client.ListBuckets(ctx, &s3.ListBucketsInput{})
if err != nil {
var apiErr smithy.APIError
if errors.As(err, &apiErr) {
return nil, fmt.Errorf("error listing buckets: %v", apiErr)
}
buckets = append(buckets, output.Buckets...)
return nil, fmt.Errorf("error listing buckets: %v", err)
}
return buckets, nil
return output.Buckets, nil
}
6 changes: 5 additions & 1 deletion pkg/remote/connparse/connparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (c *Connection) GetFullURI() string {
return c.Scheme + "://" + c.GetPathWithHost()
}

func (c *Connection) GetSchemeAndHost() string {
return c.Scheme + "://" + c.Host
}

func ParseURIAndReplaceCurrentHost(ctx context.Context, uri string) (*Connection, error) {
conn, err := ParseURI(uri)
if err != nil {
Expand Down Expand Up @@ -148,7 +152,7 @@ func ParseURI(uri string) (*Connection, error) {
}
if strings.HasPrefix(remotePath, "/~") {
remotePath = strings.TrimPrefix(remotePath, "/")
} else if len(remotePath) > 1 && !windowsDriveRegex.MatchString(remotePath) && !strings.HasPrefix(remotePath, "/") && !strings.HasPrefix(remotePath, "~") {
} else if len(remotePath) > 1 && !windowsDriveRegex.MatchString(remotePath) && !strings.HasPrefix(remotePath, "/") && !strings.HasPrefix(remotePath, "~") && !strings.HasPrefix(remotePath, "./") && !strings.HasPrefix(remotePath, "../") && !strings.HasPrefix(remotePath, ".\\") && !strings.HasPrefix(remotePath, "..\\") && remotePath != ".." {
remotePath = "/" + remotePath
}
}
Expand Down
48 changes: 48 additions & 0 deletions pkg/remote/connparse/connparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,54 @@ func TestParseURI_WSHCurrentPathShorthand(t *testing.T) {
}
}

func TestParseURI_WSHCurrentPath(t *testing.T) {
cstr := "./Documents/path/to/file"
c, err := connparse.ParseURI(cstr)
if err != nil {
t.Fatalf("failed to parse URI: %v", err)
}
expected := "./Documents/path/to/file"
if c.Path != expected {
t.Fatalf("expected path to be %q, got %q", expected, c.Path)
}
expected = "current"
if c.Host != expected {
t.Fatalf("expected host to be %q, got %q", expected, c.Host)
}
expected = "wsh"
if c.Scheme != expected {
t.Fatalf("expected scheme to be %q, got %q", expected, c.Scheme)
}
expected = "wsh://current/./Documents/path/to/file"
if c.GetFullURI() != expected {
t.Fatalf("expected full URI to be %q, got %q", expected, c.GetFullURI())
}
}

func TestParseURI_WSHCurrentPathWindows(t *testing.T) {
cstr := ".\\Documents\\path\\to\\file"
c, err := connparse.ParseURI(cstr)
if err != nil {
t.Fatalf("failed to parse URI: %v", err)
}
expected := ".\\Documents\\path\\to\\file"
if c.Path != expected {
t.Fatalf("expected path to be %q, got %q", expected, c.Path)
}
expected = "current"
if c.Host != expected {
t.Fatalf("expected host to be %q, got %q", expected, c.Host)
}
expected = "wsh"
if c.Scheme != expected {
t.Fatalf("expected scheme to be %q, got %q", expected, c.Scheme)
}
expected = "wsh://current/.\\Documents\\path\\to\\file"
if c.GetFullURI() != expected {
t.Fatalf("expected full URI to be %q, got %q", expected, c.GetFullURI())
}
}

func TestParseURI_WSHLocalShorthand(t *testing.T) {
t.Parallel()
cstr := "/~/path/to/file"
Expand Down
59 changes: 35 additions & 24 deletions pkg/remote/fileshare/fileshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"fmt"
"log"

"github.com/wavetermdev/waveterm/pkg/remote/awsconn"
"github.com/wavetermdev/waveterm/pkg/remote/connparse"
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/fstype"
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/s3fs"
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/wavefs"
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/wshfs"
"github.com/wavetermdev/waveterm/pkg/util/iochan/iochantypes"
"github.com/wavetermdev/waveterm/pkg/wshrpc"
"github.com/wavetermdev/waveterm/pkg/wshutil"
)
Expand All @@ -29,12 +28,12 @@ func CreateFileShareClient(ctx context.Context, connection string) (fstype.FileS
}
conntype := conn.GetType()
if conntype == connparse.ConnectionTypeS3 {
config, err := awsconn.GetConfig(ctx, connection)
if err != nil {
log.Printf("error getting aws config: %v", err)
return nil, nil
}
return s3fs.NewS3Client(config), conn
// config, err := awsconn.GetConfig(ctx, connection)
// if err != nil {
// log.Printf("error getting aws config: %v", err)
// return nil, nil
// }
return nil, nil
} else if conntype == connparse.ConnectionTypeWave {
return wavefs.NewWaveClient(), conn
} else if conntype == connparse.ConnectionTypeWsh {
Expand All @@ -61,10 +60,10 @@ func ReadStream(ctx context.Context, data wshrpc.FileData) <-chan wshrpc.RespOrE
return client.ReadStream(ctx, conn, data)
}

func ReadTarStream(ctx context.Context, data wshrpc.CommandRemoteStreamTarData) <-chan wshrpc.RespOrErrorUnion[[]byte] {
func ReadTarStream(ctx context.Context, data wshrpc.CommandRemoteStreamTarData) <-chan wshrpc.RespOrErrorUnion[iochantypes.Packet] {
client, conn := CreateFileShareClient(ctx, data.Path)
if conn == nil || client == nil {
return wshutil.SendErrCh[[]byte](fmt.Errorf(ErrorParsingConnection, data.Path))
return wshutil.SendErrCh[iochantypes.Packet](fmt.Errorf(ErrorParsingConnection, data.Path))
}
return client.ReadTarStream(ctx, conn, data.Opts)
}
Expand Down Expand Up @@ -110,35 +109,47 @@ func Mkdir(ctx context.Context, path string) error {
}

func Move(ctx context.Context, data wshrpc.CommandFileCopyData) error {
srcConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, data.SrcUri)
if err != nil {
return fmt.Errorf("error parsing source connection %s: %v", data.SrcUri, err)
srcClient, srcConn := CreateFileShareClient(ctx, data.SrcUri)
if srcConn == nil || srcClient == nil {
return fmt.Errorf("error creating fileshare client, could not parse source connection %s", data.SrcUri)
}
destClient, destConn := CreateFileShareClient(ctx, data.DestUri)
if destConn == nil || destClient == nil {
return fmt.Errorf("error creating fileshare client, could not parse connection %s or %s", data.SrcUri, data.DestUri)
return fmt.Errorf("error creating fileshare client, could not parse destination connection %s", data.DestUri)
}
if srcConn.Host != destConn.Host {
err := destClient.CopyRemote(ctx, srcConn, destConn, srcClient, data.Opts)
if err != nil {
return fmt.Errorf("cannot copy %q to %q: %w", data.SrcUri, data.DestUri, err)
}
return srcClient.Delete(ctx, srcConn, data.Opts.Recursive)
} else {
return srcClient.MoveInternal(ctx, srcConn, destConn, data.Opts)
}
return destClient.Move(ctx, srcConn, destConn, data.Opts)
}

func Copy(ctx context.Context, data wshrpc.CommandFileCopyData) error {
srcConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, data.SrcUri)
if err != nil {
return fmt.Errorf("error parsing source connection %s: %v", data.SrcUri, err)
srcClient, srcConn := CreateFileShareClient(ctx, data.SrcUri)
if srcConn == nil || srcClient == nil {
return fmt.Errorf("error creating fileshare client, could not parse source connection %s", data.SrcUri)
}
destClient, destConn := CreateFileShareClient(ctx, data.DestUri)
if destConn == nil || destClient == nil {
return fmt.Errorf("error creating fileshare client, could not parse connection %s or %s", data.SrcUri, data.DestUri)
return fmt.Errorf("error creating fileshare client, could not parse destination connection %s", data.DestUri)
}
if srcConn.Host != destConn.Host {
return destClient.CopyRemote(ctx, srcConn, destConn, srcClient, data.Opts)
} else {
return srcClient.CopyInternal(ctx, srcConn, destConn, data.Opts)
}
return destClient.Copy(ctx, srcConn, destConn, data.Opts)
}

func Delete(ctx context.Context, path string) error {
client, conn := CreateFileShareClient(ctx, path)
func Delete(ctx context.Context, data wshrpc.CommandDeleteFileData) error {
client, conn := CreateFileShareClient(ctx, data.Path)
if conn == nil || client == nil {
return fmt.Errorf(ErrorParsingConnection, path)
return fmt.Errorf(ErrorParsingConnection, data.Path)
}
return client.Delete(ctx, conn)
return client.Delete(ctx, conn, data.Recursive)
}

func Join(ctx context.Context, path string, parts ...string) (string, error) {
Expand Down
15 changes: 9 additions & 6 deletions pkg/remote/fileshare/fstype/fstype.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"

"github.com/wavetermdev/waveterm/pkg/remote/connparse"
"github.com/wavetermdev/waveterm/pkg/util/iochan/iochantypes"
"github.com/wavetermdev/waveterm/pkg/wshrpc"
)

Expand All @@ -18,7 +19,7 @@ type FileShareClient interface {
// ReadStream returns a stream of file data at the given path. If it's a directory, then the list of entries
ReadStream(ctx context.Context, conn *connparse.Connection, data wshrpc.FileData) <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData]
// ReadTarStream returns a stream of tar data at the given path
ReadTarStream(ctx context.Context, conn *connparse.Connection, opts *wshrpc.FileCopyOpts) <-chan wshrpc.RespOrErrorUnion[[]byte]
ReadTarStream(ctx context.Context, conn *connparse.Connection, opts *wshrpc.FileCopyOpts) <-chan wshrpc.RespOrErrorUnion[iochantypes.Packet]
// ListEntries returns the list of entries at the given path, or nothing if the path is a file
ListEntries(ctx context.Context, conn *connparse.Connection, opts *wshrpc.FileListOpts) ([]*wshrpc.FileInfo, error)
// ListEntriesStream returns a stream of entries at the given path
Expand All @@ -29,12 +30,14 @@ type FileShareClient interface {
AppendFile(ctx context.Context, conn *connparse.Connection, data wshrpc.FileData) error
// Mkdir creates a directory at the given path
Mkdir(ctx context.Context, conn *connparse.Connection) error
// Move moves the file from srcConn to destConn
Move(ctx context.Context, srcConn, destConn *connparse.Connection, opts *wshrpc.FileCopyOpts) error
// Copy copies the file from srcConn to destConn
Copy(ctx context.Context, srcConn, destConn *connparse.Connection, opts *wshrpc.FileCopyOpts) error
// Move moves the file within the same connection
MoveInternal(ctx context.Context, srcConn, destConn *connparse.Connection, opts *wshrpc.FileCopyOpts) error
// Copy copies the file within the same connection
CopyInternal(ctx context.Context, srcConn, destConn *connparse.Connection, opts *wshrpc.FileCopyOpts) error
// CopyRemote copies the file between different connections
CopyRemote(ctx context.Context, srcConn, destConn *connparse.Connection, srcClient FileShareClient, opts *wshrpc.FileCopyOpts) error
// Delete deletes the entry at the given path
Delete(ctx context.Context, conn *connparse.Connection) error
Delete(ctx context.Context, conn *connparse.Connection, recursive bool) error
esimkowitz marked this conversation as resolved.
Show resolved Hide resolved
// Join joins the given parts to the connection path
Join(ctx context.Context, conn *connparse.Connection, parts ...string) (string, error)
// GetConnectionType returns the type of connection for the fileshare
Expand Down
Loading
Loading