MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / run

Method run

pkg/blockcontroller/shellcontroller.go:259–318  ·  view source on GitHub ↗
(logCtx context.Context, bdata *waveobj.Block, blockMeta map[string]any, rtOpts *waveobj.RuntimeOpts, force bool)

Source from the content-addressed store, hash-verified

257}
258
259func (sc *ShellController) run(logCtx context.Context, bdata *waveobj.Block, blockMeta map[string]any, rtOpts *waveobj.RuntimeOpts, force bool) {
260 blocklogger.Debugf(logCtx, "[conndebug] ShellController.run() %q\n", sc.BlockId)
261 runningShellCommand := false
262 ok := sc.LockRunLock()
263 if !ok {
264 log.Printf("block %q is already executing run()\n", sc.BlockId)
265 return
266 }
267 defer func() {
268 if !runningShellCommand {
269 sc.UnlockRunLock()
270 }
271 }()
272 curStatus := sc.GetRuntimeStatus()
273 controllerName := bdata.Meta.GetString(waveobj.MetaKey_Controller, "")
274 if controllerName != BlockController_Shell && controllerName != BlockController_Cmd {
275 log.Printf("unknown controller %q\n", controllerName)
276 return
277 }
278 runOnce := getBoolFromMeta(blockMeta, waveobj.MetaKey_CmdRunOnce, false)
279 runOnStart := getBoolFromMeta(blockMeta, waveobj.MetaKey_CmdRunOnStart, true)
280 if ((runOnStart || runOnce) && curStatus.ShellProcStatus == Status_Init) || force {
281 if getBoolFromMeta(blockMeta, waveobj.MetaKey_CmdClearOnStart, false) {
282 err := HandleTruncateBlockFile(sc.BlockId)
283 if err != nil {
284 log.Printf("error truncating term blockfile: %v\n", err)
285 }
286 }
287 if runOnce {
288 ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)
289 defer cancelFn()
290 metaUpdate := map[string]any{
291 waveobj.MetaKey_CmdRunOnce: false,
292 waveobj.MetaKey_CmdRunOnStart: false,
293 }
294 err := wstore.UpdateObjectMeta(ctx, waveobj.MakeORef(waveobj.OType_Block, sc.BlockId), metaUpdate, false)
295 if err != nil {
296 log.Printf("error updating block meta (in blockcontroller.run): %v\n", err)
297 return
298 }
299 }
300 runningShellCommand = true
301 go func() {
302 defer func() {
303 panichandler.PanicHandler("blockcontroller:run-shell-command", recover())
304 }()
305 defer sc.UnlockRunLock()
306 var termSize waveobj.TermSize
307 if rtOpts != nil {
308 termSize = rtOpts.TermSize
309 } else {
310 termSize = getTermSize(bdata)
311 }
312 err := sc.DoRunShellCommand(logCtx, &RunShellOpts{TermSize: termSize}, bdata.Meta)
313 if err != nil {
314 debugLog(logCtx, "error running shell: %v\n", err)
315 }
316 }()

Callers 1

StartMethod · 0.95

Calls 13

LockRunLockMethod · 0.95
UnlockRunLockMethod · 0.95
GetRuntimeStatusMethod · 0.95
DoRunShellCommandMethod · 0.95
DebugfFunction · 0.92
UpdateObjectMetaFunction · 0.92
MakeORefFunction · 0.92
PanicHandlerFunction · 0.92
getBoolFromMetaFunction · 0.85
HandleTruncateBlockFileFunction · 0.85
getTermSizeFunction · 0.85
debugLogFunction · 0.85

Tested by

no test coverage detected