From ad2cd189b1ee8e30ee0211d0aa7087c2e45ff0cd Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Wed, 26 Jun 2024 10:15:43 -0700 Subject: [PATCH] debug: Populate history file via mounts My initial implementation of this was very naive and just used single-quote strings for history, which is almost certainly wrong most of the time. This just writes the file to the workspace directory, which is less error prone. Signed-off-by: Jon Johnson --- pkg/build/pipeline.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/build/pipeline.go b/pkg/build/pipeline.go index f204a6bbf..f71165b70 100644 --- a/pkg/build/pipeline.go +++ b/pkg/build/pipeline.go @@ -262,9 +262,11 @@ func (r *pipelineRunner) maybeDebug(ctx context.Context, fragment string, cmd [] signal.Ignore(os.Interrupt) // Populate ~/.ash_history with the current command so you can hit up arrow to repeat it. - history := fmt.Sprintf("echo '%s' >> ~/.ash_history", fragment) + if err := os.WriteFile(filepath.Join(r.config.WorkspaceDir, ".ash_history"), []byte(fragment), 0644); err != nil { + return fmt.Errorf("failed to write history file: %w", err) + } - if dbgErr := dbg.Debug(ctx, r.config, []string{"/bin/sh", "-c", fmt.Sprintf("%s && cd %s && exec /bin/sh", history, workdir)}...); dbgErr != nil { + if dbgErr := dbg.Debug(ctx, r.config, []string{"/bin/sh", "-c", fmt.Sprintf("cd %s && exec /bin/sh", workdir)}...); dbgErr != nil { return fmt.Errorf("failed to debug: %w; original error: %w", dbgErr, runErr) }