Skip to content

Commit 485b329

Browse files
committed
fix: give user access to the extracted folders
1 parent 3d6f9a3 commit 485b329

File tree

7 files changed

+22
-14
lines changed

7 files changed

+22
-14
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.

dist/setup_cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/setup_cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/utils/fs/userAccess.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { isRoot } from "../env/sudo"
2+
import { execSudo } from "../exec/sudo"
3+
4+
/// change the owner to the SUDO_USER. This is required so the user can use the folder without sudo
5+
export function folderUserAccess(folder: string) {
6+
if (
7+
(process.platform === "linux" || process.platform === "darwin") &&
8+
isRoot() &&
9+
process.env.SUDO_USER !== undefined
10+
) {
11+
execSudo("chown", ["-R", process.env.SUDO_USER, folder], folder)
12+
}
13+
}

src/utils/setup/extract.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { mkdirP } from "@actions/io"
33
import which from "which"
44
import { setupSevenZip } from "../../sevenzip/sevenzip"
55
import { warning } from "../io/io"
6+
import { folderUserAccess } from "../fs/userAccess"
67
export { extractTar, extractXar } from "@actions/tool-cache"
78

89
let sevenZip: string | undefined
910

1011
/// Extract 7z using 7z
1112
export async function extract7Zip(file: string, dest: string) {
1213
await execa(await getSevenZip(), ["x", file, `-o${dest}`, "-y"], { stdio: "inherit" })
14+
folderUserAccess(dest)
1315
return dest
1416
}
1517

@@ -53,5 +55,6 @@ export async function extractTarByExe(file: string, dest: string, flags = ["--st
5355
}
5456
}
5557

58+
folderUserAccess(dest)
5659
return dest
5760
}

src/vcpkg/vcpkg.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { existsSync } from "fs"
33
import { dirname, join } from "path"
44
import which from "which"
55
import { addPath } from "../utils/env/addEnv"
6-
import { isRoot } from "../utils/env/sudo"
7-
import { execSudo } from "../utils/exec/sudo"
86
import { addShellExtension, addShellHere } from "../utils/extension/extension"
97
import { notice } from "../utils/io/io"
108
import { setupAptPack } from "../utils/setup/setupAptPack"
@@ -14,6 +12,7 @@ import { isArch } from "../utils/env/isArch"
1412
import { hasDnf } from "../utils/env/hasDnf"
1513
import { setupDnfPack } from "../utils/setup/setupDnfPack"
1614
import { isUbuntu } from "../utils/env/isUbuntu"
15+
import { folderUserAccess } from "../utils/fs/userAccess"
1716

1817
let hasVCPKG = false
1918

@@ -54,14 +53,7 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
5453

5554
execa.sync(addShellExtension(addShellHere("bootstrap-vcpkg")), { cwd: setupDir, shell: true, stdio: "inherit" })
5655

57-
// change the owner to the SUDO_USER in setupDir. vcpkg requires this so it can install things without sudo
58-
if (
59-
(process.platform === "linux" || process.platform === "darwin") &&
60-
isRoot() &&
61-
process.env.SUDO_USER !== undefined
62-
) {
63-
execSudo("chown", ["-R", process.env.SUDO_USER, setupDir], setupDir)
64-
}
56+
folderUserAccess(setupDir)
6557

6658
await addPath(setupDir)
6759
// eslint-disable-next-line require-atomic-updates

0 commit comments

Comments
 (0)