Skip to content

Commit

Permalink
Fix for Quote in username errors dapr init #972
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmtheboss committed Jun 22, 2023
1 parent a4f924f commit af1b30a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/standalone/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ func moveFileToPath(filepath string, installLocation string) (string, error) {
p := os.Getenv("PATH")

if !strings.Contains(strings.ToLower(p), strings.ToLower(destDir)) {
utils.FixCommandWithApostrophe(&destDir)
pathCmd := "[System.Environment]::SetEnvironmentVariable('Path',[System.Environment]::GetEnvironmentVariable('Path','user') + '" + fmt.Sprintf(";%s", destDir) + "', 'user')"
_, err := utils.RunCmdAndWait("powershell", pathCmd)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,18 @@ func FindFileInDir(dirPath, fileName string) (string, error) {
}
return filePath, nil
}

// FixCommandWithApostrophe corrects the passed command which might have apostrophes in it
func FixCommandWithApostrophe(destDir *string) {
bytes := []byte(*destDir)
var result []byte

for i := 0; i < len(bytes); i++ {
result = append(result, bytes[i])
if bytes[i] == '\'' {
result = append(result, '\'')
}
}

*destDir = string(result)
}

0 comments on commit af1b30a

Please sign in to comment.