mirror of https://github.com/aminya/setup-cpp
feat: add isRoot function in addition to isSudo
This commit is contained in:
parent
bf519e6b3d
commit
860880c69a
|
@ -13,10 +13,15 @@ export function isSudo(): boolean {
|
||||||
return isSudoCache
|
return isSudoCache
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unnecessary-condition
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unnecessary-condition
|
||||||
isSudoCache = (Boolean(process.env.CI) || process.getuid?.() === 0) && which.sync("sudo", { nothrow: true }) !== null
|
isSudoCache = (Boolean(process.env.CI) || isRoot()) && which.sync("sudo", { nothrow: true }) !== null
|
||||||
return isSudoCache
|
return isSudoCache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Detect if the process has root privileges */
|
||||||
|
export function isRoot(): boolean {
|
||||||
|
return process.getuid?.() === 0
|
||||||
|
}
|
||||||
|
|
||||||
/** Prepend `sudo` to the command if sudo is available */
|
/** Prepend `sudo` to the command if sudo is available */
|
||||||
export function prependSudo(command: string) {
|
export function prependSudo(command: string) {
|
||||||
if (isSudo()) {
|
if (isSudo()) {
|
||||||
|
|
Loading…
Reference in New Issue