Skip to content

Commit f83c7d7

Browse files
committed
fix: add untildify_user and use it everywhere
1 parent 469230d commit f83c7d7

File tree

7 files changed

+22
-10
lines changed

7 files changed

+22
-10
lines changed

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/kcov/kcov.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import execa from "execa"
22
// import { join } from "path"
3-
// import untildify from "untildify"
3+
// import { untildify_user as untildify } from "./utils/path/untildify"
44
// import { setupCmake } from "../cmake/cmake"
55
import { execaSudo } from "../utils/env/sudo"
66
import { addBinExtension } from "../utils/extension/extension"
@@ -33,7 +33,7 @@ function getKcovPackageInfo(version: string): PackageInfo {
3333
extractFunction: async (file: string, dest: string): Promise<string> => {
3434
const out = await extractTarByExe(file, dest)
3535
// build after extraction using CMake
36-
// await setupCmake("3.22.0", join(untildify("~/"), "cmake"), "")
36+
// await setupCmake("3.22.0", join(untildify(""), "cmake"), "")
3737
await setupAptPack("libdw-dev")
3838
await setupAptPack("libcurl4-openssl-dev")
3939
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out })

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { setupNinja } from "./ninja/ninja"
1414
import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
1515
import { setupPython } from "./python/python"
1616
import mri from "mri"
17-
import untildify from "untildify"
17+
import { untildify_user as untildify } from "./utils/path/untildify"
1818
import { isGitHubCI } from "./utils/env/isci"
1919

2020
import semverValid from "semver/functions/valid"
@@ -101,7 +101,7 @@ export async function main(args: string[]): Promise<number> {
101101
const arch = opts.architecture ?? process.arch
102102

103103
// the installation dir for the tools that are downloaded directly
104-
const setupCppDir = process.env.SETUP_CPP_DIR ?? untildify("~/")
104+
const setupCppDir = process.env.SETUP_CPP_DIR ?? untildify("")
105105

106106
// report messages
107107
const successMessages: string[] = []

src/utils/env/addEnv.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { exportVariable } from "@actions/core"
22
import * as core from "@actions/core"
33
import execa from "execa"
44
import { isGitHubCI } from "./isci"
5-
import untildify from "untildify"
5+
import { untildify_user as untildify } from "../path/untildify"
66
import { appendFileSync } from "fs"
77
import { join } from "path"
88
import { isRoot } from "./sudo"
@@ -36,7 +36,7 @@ function addEnvSystem(name: string, val: string | undefined) {
3636
case "linux":
3737
case "darwin": {
3838
// find profile path
39-
let profile_path = untildify("~/.profile")
39+
let profile_path = untildify(".profile")
4040
if (isRoot() && typeof process.env.SUDO_USER === "string") {
4141
// use the user profile even if root
4242
profile_path = join("/home/", process.env.SUDO_USER, ".profile")

src/utils/path/addPath.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { delimiter } from "path"
33
import * as core from "@actions/core"
44
import execa from "execa"
55
import { isGitHubCI } from "../env/isci"
6-
import untildify from "untildify"
6+
import { untildify_user as untildify } from "./untildify"
77
import { appendFileSync } from "fs"
88

99
/** An add path function that works locally or inside GitHub Actions */
@@ -34,7 +34,7 @@ function addPathSystem(path: string) {
3434
}
3535
case "linux":
3636
case "darwin": {
37-
const profile_path = untildify("~/.profile")
37+
const profile_path = untildify(".profile")
3838
appendFileSync(profile_path, `\nexport PATH=${path}:$PATH\n`)
3939
core.info(`${path} was added to "${profile_path}"`)
4040
return

src/utils/path/untildify.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { join } from "path"
2+
import untildify from "untildify"
3+
import { isRoot } from "../env/sudo"
4+
5+
export function untildify_user(path: string) {
6+
if (isRoot() && typeof process.env.SUDO_USER === "string") {
7+
// use the user profile even if root
8+
return join("/home/", process.env.SUDO_USER, path)
9+
} else {
10+
return untildify(`~/${path}`)
11+
}
12+
}

0 commit comments

Comments
 (0)