Command to copy file from remote to local (#231)

* first pass of copy file

* first pass fixing up function

* fleshed out copy function, still working on display and parameters

* implemented scp like syntax

* finished implemententation of copy file - there are still issues

* more bug fixes, still running into error

* pushing waveshell concurrency and channel fixes - still need to do some qol fixes before merge

* aesthetic fixes and removed logs

* fixed bug in GetRemoteRuntimeState

* formatting small fix

* fixed pretty print bytes

* added local to local command

* small fix removing workaround

* added workaround back

* added some logs for debug

* added some more logs

* quick bug fix for update cmd race condition

* added fix for race condition

* added some more logs for debugging

* fixed up logs

* added proper fe state for dest parameter

* implemented setting status indicator output

* first pass at updating status indicators

* removed logs and small fix ups

* removed whitespace

* addressed review comments
This commit is contained in:
Cole Lashley
2024-02-08 17:37:23 -03:00
committed by GitHub
parent ff855cf308
commit b37f7f722e
6 changed files with 579 additions and 11 deletions
+2 -6
View File
@@ -156,16 +156,12 @@ func (p *PacketParser) trySendRpcResponse(pk PacketType) bool {
return false
}
p.Lock.Lock()
defer p.Lock.Unlock()
entry := p.RpcMap[respId]
p.Lock.Unlock()
if entry == nil {
return false
}
// nonblocking send
select {
case entry.RespCh <- respPk:
default:
}
entry.RespCh <- respPk
return true
}
File diff suppressed because it is too large Load Diff
+5
View File
@@ -24,6 +24,11 @@ const (
R_RemoteConnected = 16
)
const (
ConnectedRemote = "connected"
LocalRemote = "local"
)
type resolvedIds struct {
SessionId string
ScreenId string
+12 -5
View File
@@ -50,6 +50,7 @@ const RemoteTermRows = 8
const RemoteTermCols = 80
const PtyReadBufSize = 100
const RemoteConnectTimeout = 15 * time.Second
const RpcIterChannelSize = 100
var envVarsToStrip map[string]bool = map[string]bool{
"PROMPT": true,
@@ -665,7 +666,12 @@ func (msh *MShellProc) GetRemoteRuntimeState() RemoteRuntimeState {
if vars["remoteuser"] == "root" || vars["sudo"] == "1" {
vars["isroot"] = "1"
}
state.RemoteVars = vars
varsCopy := make(map[string]string)
// deep copy so that concurrent calls don't collide on this data
for key, value := range vars {
varsCopy[key] = value
}
state.RemoteVars = varsCopy
state.ActiveShells = msh.StateMap.GetShells()
return state
}
@@ -1203,6 +1209,10 @@ func (msh *MShellProc) ReInit(ctx context.Context, shellType string) (*packet.Sh
return ssPk, nil
}
func (msh *MShellProc) WriteFile(ctx context.Context, writePk *packet.WriteFilePacketType) (*packet.RpcResponseIter, error) {
return msh.PacketRpcIter(ctx, writePk)
}
func (msh *MShellProc) StreamFile(ctx context.Context, streamPk *packet.StreamFilePacketType) (*packet.RpcResponseIter, error) {
return msh.PacketRpcIter(ctx, streamPk)
}
@@ -1886,7 +1896,6 @@ func RunCommand(ctx context.Context, rcOpts RunCommandOpts, runPacket *packet.Ru
RunPacket: runPacket,
})
go pushNumRunningCmdsUpdate(&runPacket.CK, 1)
return cmd, func() { removeCmdWait(runPacket.CK) }, nil
}
@@ -1925,7 +1934,7 @@ func (msh *MShellProc) PacketRpcIter(ctx context.Context, pk packet.RpcPacketTyp
return nil, fmt.Errorf("PacketRpc passed nil packet")
}
reqId := pk.GetReqId()
msh.ServerProc.Output.RegisterRpc(reqId)
msh.ServerProc.Output.RegisterRpcSz(reqId, RpcIterChannelSize)
err := msh.ServerProc.Input.SendPacketCtx(ctx, pk)
if err != nil {
return nil, err
@@ -2064,8 +2073,6 @@ func (msh *MShellProc) handleCmdDonePacket(donePk *packet.CmdDonePacketType) {
// fall-through (nothing to do)
}
}
go pushNumRunningCmdsUpdate(&donePk.CK, -1)
sstore.MainBus.SendUpdate(update)
return
}
+1
View File
@@ -950,6 +950,7 @@ func UpdateCmdDoneInfo(ctx context.Context, ck base.CommandKey, donePk *packet.C
// This is not a fatal error, so just log it
log.Printf("error setting status indicator level after done packet: %v\n", err)
}
IncrementNumRunningCmds_Update(update, screenId, -1)
return update, nil
}
+4
View File
@@ -1100,6 +1100,10 @@ type RemoteType struct {
OpenAIOpts *OpenAIOptsType `json:"openaiopts,omitempty"`
}
func (r *RemoteType) IsLocal() bool {
return r.Local && !r.IsSudo()
}
func (r *RemoteType) IsSudo() bool {
return r.SSHOpts != nil && r.SSHOpts.IsSudo
}