From 80b7087c8f8995cbadd038661b0dcdd39c7d08d5 Mon Sep 17 00:00:00 2001 From: kitsunyan Date: Sun, 20 May 2018 14:07:35 +0300 Subject: Allow to preserve built packages to user cache dir Preserving is disabled by default now. --- lib/install.nim | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'lib/install.nim') 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: "".} template perror*: void = perror(getAppFilename()) -- cgit v1.2.3-70-g09d2