aboutsummaryrefslogtreecommitdiff
path: root/src/feature/syncinstall.nim
diff options
context:
space:
mode:
authorzqqw2020-10-26 02:11:42 +0000
committerzqqw2020-10-26 02:11:42 +0000
commit0601052833bfb97cc178cdbd7aa150ecec4c7e5b (patch)
tree3dfe606433ea45dc48e106a8caf0d221f1e1a5f2 /src/feature/syncinstall.nim
parentf2a93bea278e9f43cad98ca8e74f9a423f36e333 (diff)
execRedirect - pipe stdout from child
Diffstat (limited to 'src/feature/syncinstall.nim')
-rw-r--r--src/feature/syncinstall.nim23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim
index 813eb45..8f26d0d 100644
--- a/src/feature/syncinstall.nim
+++ b/src/feature/syncinstall.nim
@@ -305,6 +305,17 @@ template dropPrivilegesAndChdir(path: Option[string], body: untyped): int =
printError(config.color, tr"failed to drop privileges")
quit(1)
+template dropPrivRedirectAndChdir(path: Option[string], body: untyped): int =
+ if dropPrivRedirect():
+ if path.isNone or chdir(path.unsafeGet) == 0:
+ body
+ else:
+ printError(config.color, tr"chdir failed: $#" % [path.unsafeGet])
+ quit(1)
+ else:
+ printError(config.color, tr"failed to drop privileges")
+ quit(1)
+
template createViewTag(repo: string, base: string): string =
"view-" & repo & "/" & base
@@ -376,8 +387,8 @@ proc editLoop(config: Config, repo: string, base: string, repoPath: string,
let (hasChanges, noTag) = if repo == config.aurRepo: (block:
let revisions = forkWaitRedirect(() => (block:
- dropPrivilegesAndChdir(none(string)):
- execResult(gitCmd, "-C", repoPath, "rev-list", tag & "..@")))
+ dropPrivRedirectAndChdir(none(string)):
+ execRedirect(gitCmd, "-C", repoPath, "rev-list", tag & "..@")))
if revisions.code != 0:
(false, true)
@@ -385,8 +396,8 @@ proc editLoop(config: Config, repo: string, base: string, repoPath: string,
(false, false)
else: (block:
let diff = forkWaitRedirect(() => (block:
- dropPrivilegesAndChdir(none(string)):
- execResult(gitCmd, "-C", repoPath, "diff", tag & "..@", gitSubdir.get("."))))
+ dropPrivRedirectAndChdir(none(string)):
+ execRedirect(gitCmd, "-C", repoPath, "diff", tag & "..@", gitSubdir.get("."))))
(diff.output.len > 0, false)))
else:
(false, true)
@@ -436,8 +447,8 @@ proc buildLoop(config: Config, pkgInfos: seq[PackageInfo], skipDeps: bool,
let envExt = getEnv("PKGEXT")
let confExt = if envExt.len == 0:
forkWaitRedirect(() => (block:
- dropPrivilegesAndChdir(none(string)):
- execResult(bashCmd, "-c",
+ dropPrivRedirectAndChdir(none(string)):
+ execRedirect(bashCmd, "-c",
"source \"$@\" && echo \"$PKGEXT\"",
"bash", workConfFile)))
.output.optFirst.get("")