fix: allow expansion from log_path for coder_script (#9868)

This commit is contained in:
Kyle Carberry
2023-09-25 18:45:55 -05:00
committed by GitHub
parent 89292264be
commit 20bfe6e9e5
+14
View File
@@ -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)
}