diff options
author | kitsunyan | 2018-05-20 11:07:35 +0000 |
---|---|---|
committer | kitsunyan | 2018-05-20 11:07:35 +0000 |
commit | 80b7087c8f8995cbadd038661b0dcdd39c7d08d5 (patch) | |
tree | 85e1f3d2a419ff6f5ff1b9a2c9a592d453e0d25d | |
parent | 396e9f44c4f5a79c7b9238835599387f6ff418fe (diff) |
Allow to preserve built packages to user cache dir
Preserving is disabled by default now.
-rw-r--r-- | doc/pakku.conf.5.txt | 5 | ||||
-rw-r--r-- | lib/install.nim | 21 | ||||
-rw-r--r-- | pakku.conf | 2 | ||||
-rw-r--r-- | src/common.nim | 2 | ||||
-rw-r--r-- | src/config.nim | 14 | ||||
-rw-r--r-- | src/feature/syncinstall.nim | 15 |
6 files changed, 47 insertions, 12 deletions
diff --git a/doc/pakku.conf.5.txt b/doc/pakku.conf.5.txt index c9666a4..830f212 100644 --- a/doc/pakku.conf.5.txt +++ b/doc/pakku.conf.5.txt @@ -44,6 +44,11 @@ Options content of PKGBUILD and other files. Pressing enter key will give the positive answer unless this option is specified. +*PreserveBuilt =* Internal | User | Disabled:: + If set to Internal, built packages will be copied to pacman cache dir. + If set to User, built packages will be copied to UserCacheDir. + If set to Disabled (the default), built packages will not be preserved. + *PreBuildCommand =* command:: This command will be executed in package directory before building, allowing you to modify PKGBUILD or perform other necessary actions. 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()) @@ -10,4 +10,6 @@ PrintAurNotFound #SudoExec #ViewNoDefault +#PreserveBuilt = Disabled + #PreBuildCommand = diff --git a/src/common.nim b/src/common.nim index 62966ee..ca6d8c9 100644 --- a/src/common.nim +++ b/src/common.nim @@ -5,7 +5,7 @@ import type CacheKind* {.pure.} = enum - repositories + repositories, packages BareKind* {.pure.} = enum pkg, repo diff --git a/src/config.nim b/src/config.nim index b4b9c9a..f0c8710 100644 --- a/src/config.nim +++ b/src/config.nim @@ -1,5 +1,5 @@ import - future, options, posix, re, sets, strutils, tables, + future, options, posix, re, sequtils, sets, strutils, tables, utils type @@ -8,6 +8,11 @@ type colorAuto = "auto", colorAlways = "always" + PreserveBuilt* {.pure.} = enum + internal = "Internal", + user = "User", + disabled = "Disabled" + CommonConfig* = object of RootObj dbs*: seq[string] arch*: string @@ -39,6 +44,7 @@ type printAurNotFound*: bool sudoExec*: bool viewNoDefault*: bool + preserveBuilt*: PreserveBuilt preBuildCommand*: Option[string] proc readConfigFile*(configFile: string): @@ -144,6 +150,9 @@ proc obtainConfig*(config: PacmanConfig): Config = let printAurNotFound = options.hasKey("PrintAurNotFound") let sudoExec = options.hasKey("SudoExec") let viewNoDefault = options.hasKey("ViewNoDefault") + let preserveBuilt = toSeq(enumerate[PreserveBuilt]()) + .filter(o => some($o) == options.opt("PreserveBuilt")) + .optLast.get(PreserveBuilt.disabled) let preBuildCommand = options.opt("PreBuildCommand") Config(root: root, db: db, cache: cache, @@ -153,4 +162,5 @@ proc obtainConfig*(config: PacmanConfig): Config = verbosePkgList: config.verbosePkgList, pgpKeyserver: config.pgpKeyserver, ignorePkgs: config.ignorePkgs, ignoreGroups: config.ignoreGroups, aurComments: aurComments, checkIgnored: checkIgnored, printAurNotFound: printAurNotFound, - sudoExec: sudoExec, viewNoDefault: viewNoDefault, preBuildCommand: preBuildCommand) + sudoExec: sudoExec, viewNoDefault: viewNoDefault, preserveBuilt: preserveBuilt, + preBuildCommand: preBuildCommand) diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim index 4d0a564..269777a 100644 --- a/src/feature/syncinstall.nim +++ b/src/feature/syncinstall.nim @@ -585,7 +585,20 @@ proc installGroupFromSources(config: Config, commonArgs: seq[Argument], let asdeps = install.filter(p => not (p.name in explicits)).map(p => p.file) let asexplicit = install.filter(p => p.name in explicits).map(p => p.file) - let installParams = sudoPrefix & (pkgLibDir & "/install") & config.cache & + let (cacheDir, cacheUser, cacheGroup) = if config.preserveBuilt == PreserveBuilt.internal: + (config.cache, 0, 0) + elif config.preserveBuilt == PreserveBuilt.user: (block: + let error = ensureUserCacheOrError(config, CacheKind.packages, true) + for e in error: printError(config.color, e) + let user = initialUser.get(currentUser) + let dir = config.userCacheInitial.cache(CacheKind.packages) + (dir, user.uid, user.gid)) + else: + # pass -1 values to disable caching + ("", -1, -1) + + let installParams = sudoPrefix & (pkgLibDir & "/install") & + cacheDir & $cacheUser & $cacheGroup & $pacmanParams.len & pacmanParams & $asdeps.len & asdeps & $asexplicit.len & asexplicit let code = forkWait(() => execResult(installParams)) |