8000 feat: check for .ps1 dotfiles scripts on windows by aslilac · Pull Request #16785 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: check for .ps1 dotfiles scripts on windows #16785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 4, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ok but the version that actually works now
  • Loading branch information
aslilac committed Mar 4, 2025
commit f0f4ef661165a185351ed19a43c17324165d8268
24 changes: 16 additions & 8 deletions cli/dotfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -186,21 +187,28 @@ func (r *RootCmd) dotfiles() *serpent.Command {

_, _ = fmt.Fprintf(inv.Stdout, "Running %s...\n", script)

// Check if the script is executable and notify on error
scriptPath := filepath.Join(dotfilesDir, script)
fi, err := os.Stat(scriptPath)
if err != nil {
return xerrors.Errorf("stat %s: %w", scriptPath, err)
}

if fi.Mode()&0o111 == 0 {
return xerrors.Errorf("script %q does not have execute permissions", script)
// Permissions checks will always fail on Windows, since it doesn't have
// conventional Unix file system permissions.
if runtime.GOOS != "windows" {
// Check if the script is executable and notify on error
fi, err := os.Stat(scriptPath)
if err != nil {
return xerrors.Errorf("stat %s: %w", scriptPath, err)
}
if fi.Mode()&0o111 == 0 {
return xerrors.Errorf("script %q does not have execute permissions", script)
}
}

// it is safe to use a variable command here because it's from
// a filtered list of pre-approved install scripts
// nolint:gosec
scriptCmd := exec.CommandContext(inv.Context(), filepath.Join(dotfilesDir, script))
scriptCmd := exec.CommandContext(inv.Context(), scriptPath)
if runtime.GOOS == "windows" {
scriptCmd = exec.CommandContext(inv.Context(), "powershell", "-NoLogo", scriptPath)
513B }
scriptCmd.Dir = dotfilesDir
scriptCmd.Stdout = inv.Stdout
scriptCmd.Stderr = inv.Stderr
Expand Down
Loading
0