From 0b14a64ada7a1489d5f6e07d97bf6b900b573184 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Mon, 25 Sep 2023 23:38:25 +0000 Subject: [PATCH] fix: allow expansion from `log_path` for `coder_script` --- agent/agentscripts/agentscripts.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/agent/agentscripts/agentscripts.go b/agent/agentscripts/agentscripts.go index 970b8004e9a60..98a6901ebbbc4 100644 --- a/agent/agentscripts/agentscripts.go +++ b/agent/agentscripts/agentscripts.go @@ -7,6 +7,7 @@ import ( "io" "os" "os/exec" + "os/user" "path/filepath" "sync" "sync/atomic" @@ -133,6 +134,19 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript) if logPath == "" { logPath = fmt.Sprintf("coder-script-%s.log", script.LogSourceID) } + if logPath[0] == '~' { + // First we check the environment. + homeDir, err := os.UserHomeDir() + if err != nil { + u, err := user.Current() + if err != nil { + return xerrors.Errorf("current user: %w", err) + } + homeDir = u.HomeDir + } + logPath = filepath.Join(homeDir, logPath[1:]) + } + logPath = os.ExpandEnv(logPath) if !filepath.IsAbs(logPath) { logPath = filepath.Join(r.LogDir, logPath) }