Skip to content

Commit

Permalink
fix: prevent adding /usr/bin if it is already on the PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 1, 2023
1 parent 511e70e commit 307b917
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 44 deletions.
24 changes: 12 additions & 12 deletions dist/actions/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/actions/setup-cpp.js.map

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions dist/modern/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.js.map

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/utils/env/addEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,27 @@ function escapeString(valGiven: string, shouldEscapeSpace: boolean = false) {
return escapeQuote(spaceEscaped, '"', "\\")
}

const ignoredPaths = [/\/usr\/bin\/?/, /\/usr\/local\/bin\/?/]

/** Skip adding /usr/bin to PATH if it is already there */
function isIgnoredPath(path: string) {
if (ignoredPaths.some((checkedPath) => checkedPath.test(path))) {
const paths = process.env.PATH?.split(delimiter) ?? []
return paths.includes(path)
}
return false
}

/**
* Add a path to the PATH environment variable.
*
* This function is cross-platforms and works in all the local or CI systems.
*/
export async function addPath(path: string) {
if (isIgnoredPath(path)) {
return
}

process.env.PATH = `${path}${delimiter}${process.env.PATH}`
try {
if (GITHUB_ACTIONS) {
Expand Down

0 comments on commit 307b917

Please sign in to comment.