aboutsummaryrefslogtreecommitdiff
path: root/src/config.nim
diff options
context:
space:
mode:
authorkitsunyan2018-05-19 04:46:13 +0000
committerkitsunyan2018-05-19 04:46:13 +0000
commite301fefe660f3cb1f27f924e04d25db5db9f28a6 (patch)
tree5ec2d010d018c120fe748f8ef6eae5015d257fc2 /src/config.nim
parent921c83730f425dfb6b7db459044db839124dcff4 (diff)
Add user cache dir
Diffstat (limited to 'src/config.nim')
-rw-r--r--src/config.nim20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/config.nim b/src/config.nim
index 19dc0d6..b4b9c9a 100644
--- a/src/config.nim
+++ b/src/config.nim
@@ -29,6 +29,8 @@ type
root*: string
db*: string
cache*: string
+ userCacheInitial*: string
+ userCacheCurrent*: string
tmpRootInitial*: string
tmpRootCurrent*: string
color*: bool
@@ -119,12 +121,23 @@ proc obtainConfig*(config: PacmanConfig): Config =
let cache = config.cache
let color = config.colorMode.get
- proc obtainTmpDir(user: User): string =
- options.opt("TmpDir").get("/tmp/pakku-${USER}")
+ proc handleDirPattern(dirPattern: string, user: User): string =
+ dirPattern
.replace("${UID}", $user.uid)
.replace("${USER}", user.name)
+ .replace("${HOME}", user.home)
+ .replace("$$", "$")
+
+ proc obtainUserCacheDir(user: User): string =
+ options.opt("UserCacheDir").get("${HOME}/.cache/pakku").handleDirPattern(user)
+
+ proc obtainTmpDir(user: User): string =
+ options.opt("TmpDir").get("/tmp/pakku-${USER}").handleDirPattern(user)
- let tmpRootInitial = obtainTmpDir(initialUser.get(currentUser))
+ let initialOrCurrentUser = initialUser.get(currentUser)
+ let userCacheInitial = obtainUserCacheDir(initialOrCurrentUser)
+ let userCacheCurrent = obtainUserCacheDir(currentUser)
+ let tmpRootInitial = obtainTmpDir(initialOrCurrentUser)
let tmpRootCurrent = obtainTmpDir(currentUser)
let aurComments = options.hasKey("AurComments")
let checkIgnored = options.hasKey("CheckIgnored")
@@ -134,6 +147,7 @@ proc obtainConfig*(config: PacmanConfig): Config =
let preBuildCommand = options.opt("PreBuildCommand")
Config(root: root, db: db, cache: cache,
+ userCacheInitial: userCacheInitial, userCacheCurrent: userCacheCurrent,
tmpRootInitial: tmpRootInitial, tmpRootCurrent: tmpRootCurrent, color: color,
dbs: config.dbs, arch: config.arch, debug: config.debug, progressBar: config.progressBar,
verbosePkgList: config.verbosePkgList, pgpKeyserver: config.pgpKeyserver,