aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorkitsunyan2018-05-20 11:07:35 +0000
committerkitsunyan2018-05-20 11:07:35 +0000
commit80b7087c8f8995cbadd038661b0dcdd39c7d08d5 (patch)
tree85e1f3d2a419ff6f5ff1b9a2c9a592d453e0d25d /lib
parent396e9f44c4f5a79c7b9238835599387f6ff418fe (diff)
Allow to preserve built packages to user cache dir
Preserving is disabled by default now.
Diffstat (limited to 'lib')
-rw-r--r--lib/install.nim21
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/install.nim b/lib/install.nim
index cec9ca1..67e5f96 100644
--- a/lib/install.nim
+++ b/lib/install.nim
@@ -2,7 +2,9 @@ import future, os, posix, sequtils, strutils
let params = commandLineParams()
let destination = params[0]
-let paramsStart = 1
+let uid = params[1].parseInt
+let gid = params[2].parseInt
+let paramsStart = 3
proc splitCommands(index: int, res: seq[seq[string]]): seq[seq[string]] =
if index < params.len:
@@ -15,13 +17,16 @@ proc splitCommands(index: int, res: seq[seq[string]]): seq[seq[string]] =
let commands = splitCommands(paramsStart, @[])
let targets = lc[x | (y <- commands[1 .. ^1], x <- y), string]
-for file in targets:
- try:
- let index = file.rfind("/")
- let name = if index >= 0: file[index + 1 .. ^1] else: file
- copyFile(file, destination & "/" & name)
- except:
- discard
+if uid >= 0 and gid >= 0:
+ for file in targets:
+ try:
+ let index = file.rfind("/")
+ let name = if index >= 0: file[index + 1 .. ^1] else: file
+ let dest = destination & "/" & name
+ copyFile(file, dest)
+ discard chown(dest, (Uid) uid, (Gid) gid)
+ except:
+ discard
proc perror*(s: cstring): void {.importc, header: "<stdio.h>".}
template perror*: void = perror(getAppFilename())