aboutsummaryrefslogtreecommitdiff
path: root/src/main.nim
diff options
context:
space:
mode:
authorkitsunyan2018-04-08 20:54:18 +0000
committerkitsunyan2018-04-08 20:54:18 +0000
commit72b8161f2f37a0a6b091e300810a40e9a775c64b (patch)
tree2c127c810f6574da500dc3400b4a46f377640c26 /src/main.nim
parent52ab10b957d557f269363d5441a6fa34a2542b21 (diff)
Allow running via sudo
Diffstat (limited to 'src/main.nim')
-rw-r--r--src/main.nim10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/main.nim b/src/main.nim
index b5d700b..26e2908 100644
--- a/src/main.nim
+++ b/src/main.nim
@@ -87,12 +87,12 @@ proc handleSync(args: seq[Argument], config: Config): int =
let isNonDefaultRoot = not config.isRootDefault
let isDowngrade = args.count((some("u"), "sysupgrade")) >= 2
let isSkipDeps = args.check((some("d"), "nodeps"))
- let isRoot = getuid() == 0
+ let isRootNoDrop = currentUser.uid == 0 and not canDropPrivileges()
let build = args.check((none(string), "build"))
let noaur = args.check((none(string), "noaur"))
- let noBuild = isNonDefaultRoot or isDowngrade or isSkipDeps or isRoot
+ let noBuild = isNonDefaultRoot or isDowngrade or isSkipDeps or isRootNoDrop
if build and noBuild:
if isNonDefaultRoot:
@@ -104,7 +104,7 @@ proc handleSync(args: seq[Argument], config: Config): int =
elif isSkipDeps:
printError(config.color, tr"dependency check is skipped" & " -- " &
tr"building is not allowed")
- elif isRoot:
+ elif isRootNoDrop:
printError(config.color, tr"running as root" & " -- " &
tr"building is not allowed")
1
@@ -121,7 +121,7 @@ proc handleSync(args: seq[Argument], config: Config): int =
elif isSkipDeps:
printWarning(config.color, tr"dependency check is skipped" & " -- " &
tr"'$#' is assumed" % ["--noaur"])
- elif isRoot:
+ elif isRootNoDrop:
printWarning(config.color, tr"running as root" & " -- " &
tr"'$#' is assumed" % ["--noaur"])
@@ -171,7 +171,7 @@ proc handleHelp(operation: OperationType) =
.map(o => @["-" & o.pair.short.get])
.optFirst.get(@[]) & @["-h"]
- let lines = runProgram(pacmanCmd & operationArgs)
+ let (lines, _) = forkWaitRedirect(() => execResult(pacmanCmd & operationArgs))
for line in lines:
echo(line.replace(re"\bpacman\b", "pakku"))