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 --> <!-- 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 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 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 - path (`string`) - The path to give the user access to
**returns:** void **returns:** Promise<void>
<!-- INSERT GENERATED DOCS END --> <!-- INSERT GENERATED DOCS END -->

View File

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

View File

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

View File

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

View File

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