Skip to content

Commit 20bfe6e

Browse files
authored
fix: allow expansion from log_path for coder_script (#9868)
1 parent 8929226 commit 20bfe6e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

agent/agentscripts/agentscripts.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"os"
99
"os/exec"
10+
"os/user"
1011
"path/filepath"
1112
"sync"
1213
"sync/atomic"
@@ -133,6 +134,19 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript)
133134
if logPath == "" {
134135
logPath = fmt.Sprintf("coder-script-%s.log", script.LogSourceID)
135136
}
137+
if logPath[0] == '~' {
138+
// First we check the environment.
139+
homeDir, err := os.UserHomeDir()
140+
if err != nil {
141+
u, err := user.Current()
142+
if err != nil {
143+
return xerrors.Errorf("current user: %w", err)
144+
}
145+
homeDir = u.HomeDir
146+
}
147+
logPath = filepath.Join(homeDir, logPath[1:])
148+
}
149+
logPath = os.ExpandEnv(logPath)
136150
if !filepath.IsAbs(logPath) {
137151
logPath = filepath.Join(r.LogDir, logPath)
138152
}

0 commit comments

Comments
 (0)