MCPcopy
hub / github.com/wavetermdev/waveterm / CpWshToRemote

Function CpWshToRemote

pkg/wslconn/wsl-util.go:132–220  ·  view source on GitHub ↗
(ctx context.Context, client *wsl.Distro, clientOs string, clientArch string)

Source from the content-addressed store, hash-verified

130}
131
132func CpWshToRemote(ctx context.Context, client *wsl.Distro, clientOs string, clientArch string) error {
133 wshLocalPath, err := shellutil.GetLocalWshBinaryPath(wavebase.WaveVersion, clientOs, clientArch)
134 if err != nil {
135 return err
136 }
137 // warning: does not work on windows remote yet
138 bashInstalled, err := hasBashInstalled(ctx, client)
139 if err != nil {
140 return err
141 }
142
143 var selectedTemplatesRaw map[string]string
144 if bashInstalled {
145 selectedTemplatesRaw = installTemplatesRawBash
146 } else {
147 log.Printf("bash is not installed on remote. attempting with default shell")
148 selectedTemplatesRaw = installTemplatesRawDefault
149 }
150
151 // I need to use toSlash here to force unix keybindings
152 // this means we can't guarantee it will work on a remote windows machine
153 var installWords = map[string]string{
154 "installDir": filepath.ToSlash(filepath.Dir(wavebase.RemoteFullWshBinPath)),
155 "tempPath": wavebase.RemoteFullWshBinPath + ".temp",
156 "installPath": wavebase.RemoteFullWshBinPath,
157 }
158
159 blocklogger.Infof(ctx, "[conndebug] copying %q to remote server %q\n", wshLocalPath, wavebase.RemoteFullWshBinPath)
160 installStepCmds := make(map[string]*CancellableCmd)
161 for cmdName, selectedTemplateRaw := range selectedTemplatesRaw {
162 cancellableCmd, err := makeCancellableCommand(ctx, client, selectedTemplateRaw, installWords)
163 if err != nil {
164 return err
165 }
166 installStepCmds[cmdName] = cancellableCmd
167 }
168
169 _, err = installStepCmds["mkdir"].Cmd.Output()
170 if err != nil {
171 return err
172 }
173
174 // the cat part of this is complicated since it requires stdin
175 catCmd := installStepCmds["cat"].Cmd
176 catStdin, err := catCmd.StdinPipe()
177 if err != nil {
178 return err
179 }
180 err = catCmd.Start()
181 if err != nil {
182 return err
183 }
184 input, err := os.Open(wshLocalPath)
185 if err != nil {
186 return fmt.Errorf("cannot open local file %s to send to host: %v", wshLocalPath, err)
187 }
188 go func() {
189 defer func() {

Callers 2

UpdateWshMethod · 0.70
InstallWshMethod · 0.70

Calls 13

GetLocalWshBinaryPathFunction · 0.92
InfofFunction · 0.92
PanicHandlerFunction · 0.92
hasBashInstalledFunction · 0.85
makeCancellableCommandFunction · 0.85
OutputMethod · 0.80
OpenMethod · 0.80
CopyMethod · 0.80
StdinPipeMethod · 0.65
StartMethod · 0.65
KillMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected