fix: async grantUserWriteAccess

This commit is contained in:
Amin Yahyaabadi 2023-09-07 13:47:30 -07:00
parent 5126444593
commit 99191e7285
20 changed files with 45 additions and 45 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -18,7 +18,7 @@ npm install --save user-access
<!-- INSERT GENERATED DOCS START -->
### `giveUserAccess` (function)
### `grantUserWriteAccess` (function)
Give the user access to the given path and its sub-directories. It changes the owner to the SUDO_USER. This allows
the user to use the folder without sudo
@ -27,7 +27,7 @@ the user to use the folder without sudo
- path (`string`) - The path to give the user access to
**returns:** void
**returns:** Promise<void>
<!-- INSERT GENERATED DOCS END -->

View File

@ -1,4 +1,4 @@
import { isSudo, execRootSync } from "admina"
import { isSudo, execRoot } from "admina"
import { statSync } from "fs"
/**
@ -7,14 +7,14 @@ import { statSync } from "fs"
*
* @param path The path to give the user access to
*/
export function giveUserAccess(path: string) {
export async function grantUserWriteAccess(path: string) {
if (
(process.platform === "linux" || process.platform === "darwin") &&
isSudo() &&
process.env.SUDO_USER !== undefined
) {
const isDirectory = statSync(path).isDirectory()
execRootSync("chown", [...(isDirectory ? ["-R"] : []), process.env.SUDO_USER, path], {
await execRoot("chown", [...(isDirectory ? ["-R"] : []), process.env.SUDO_USER, path], {
cwd: path,
stdio: "inherit",
shell: true,

View File

@ -6,7 +6,7 @@ import { error, warning } from "ci-log"
import { execPowershell } from "exec-powershell"
import { delimiter } from "path"
import escapeSpace from "escape-path-with-spaces"
import { giveUserAccess } from "user-access"
import { grantUserWriteAccess } from "user-access"
import escapeQuote from "escape-quotes"
import { pathExists } from "path-exists"
@ -212,7 +212,7 @@ export async function finalizeCpprc() {
writeFileSync(cpprc_path, unique_entries.join("\n"))
try {
giveUserAccess(cpprc_path)
grantUserWriteAccess(cpprc_path)
} catch {
// ignore
}

View File

@ -3,7 +3,7 @@ import { mkdirP } from "@actions/io"
import which from "which"
import { setupSevenZip } from "../../sevenzip/sevenzip"
import { warning } from "ci-log"
import { giveUserAccess } from "user-access"
import { grantUserWriteAccess } from "user-access"
export { extractTar, extractXar } from "@actions/tool-cache"
let sevenZip: string | undefined
@ -11,7 +11,7 @@ let sevenZip: string | undefined
/// Extract 7z using 7z
export async function extract7Zip(file: string, dest: string) {
await execa(await getSevenZip(), ["x", file, `-o${dest}`, "-y"], { stdio: "inherit" })
giveUserAccess(dest)
grantUserWriteAccess(dest)
return dest
}
@ -55,6 +55,6 @@ export async function extractTarByExe(file: string, dest: string, flags = ["--st
}
}
giveUserAccess(dest)
grantUserWriteAccess(dest)
return dest
}

View File

@ -2,7 +2,7 @@ import { execaSync } from "execa"
import { notice } from "ci-log"
import { pathExists } from "path-exists"
import { addShExt, addShRelativePrefix, dirname, join } from "patha"
import { giveUserAccess } from "user-access"
import { grantUserWriteAccess } from "user-access"
import which from "which"
import { addPath } from "../utils/env/addEnv"
import { hasDnf } from "../utils/env/hasDnf"
@ -62,7 +62,7 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
stdio: "inherit",
})
giveUserAccess(setupDir)
grantUserWriteAccess(setupDir)
await addPath(setupDir)
// eslint-disable-next-line require-atomic-updates