aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.nim10
-rw-r--r--src/config.nim109
-rw-r--r--src/feature/syncinfo.nim2
-rw-r--r--src/feature/syncinstall.nim28
-rw-r--r--src/feature/syncsearch.nim2
-rw-r--r--src/feature/syncsource.nim4
-rw-r--r--src/main.nim2
-rw-r--r--src/pacman.nim26
8 files changed, 90 insertions, 93 deletions
diff --git a/src/common.nim b/src/common.nim
index ead9b4b..5bd9e63 100644
--- a/src/common.nim
+++ b/src/common.nim
@@ -116,7 +116,7 @@ proc filterNotFoundSyncTargets*[T: RpcPackageInfo](syncTargets: seq[SyncPackageT
pkgInfoReferencesTable, upToDateNeededTable, aurRepo)
proc printSyncNotFound*(config: Config, notFoundTargets: seq[SyncPackageTarget]) =
- let dbs = config.dbs.toSet
+ let dbs = config.common.dbs.toSet
for target in notFoundTargets:
if target.repo.isNone or target.repo == some(config.aurRepo) or target.repo.unsafeGet in dbs:
@@ -463,7 +463,7 @@ proc obtainSrcInfo*(path: string): string =
proc reloadPkgInfos*(config: Config, path: string, pkgInfos: seq[PackageInfo]): seq[PackageInfo] =
let srcInfo = obtainSrcInfo(path)
- let res = parseSrcInfo(pkgInfos[0].repo, srcInfo, config.arch,
+ let res = parseSrcInfo(pkgInfos[0].repo, srcInfo, config.common.arch,
pkgInfos[0].gitUrl, pkgInfos[0].gitSubdir)
if res.len > 0:
res
@@ -548,7 +548,7 @@ proc clonePackageRepoInternal(config: Config, base: string, version: string,
"clone", "-q", url, "--single-branch", base)
else:
quit(1))) == 0:
- let commit = bisectVersion(repoPath, config.debug, none(string),
+ let commit = bisectVersion(repoPath, config.common.debug, none(string),
"source", git.path, version, dropPrivileges)
if commit.isNone:
@@ -609,7 +609,7 @@ proc obtainBuildPkgInfosInternal(config: Config, bases: seq[LookupBaseGroup],
if repoPath.isSome:
let srcInfo = obtainSrcInfo(repoPath.unsafeGet & "/" & git.path)
- let pkgInfos = parseSrcInfo(repo, srcInfo, config.arch,
+ let pkgInfos = parseSrcInfo(repo, srcInfo, config.common.arch,
git.url, some(git.path))
.filter(i => i.version == version)
(pkgInfos, repoPath)
@@ -731,7 +731,7 @@ proc cloneAurReposWithPackageInfos*(config: Config, rpcInfos: seq[RpcPackageInfo
except:
""
- let addPkgInfos = parseSrcInfo(config.aurRepo, srcInfos, config.arch,
+ let addPkgInfos = parseSrcInfo(config.aurRepo, srcInfos, config.common.arch,
bases[index].gitUrl, none(string), rpcInfos)
if keepRepos:
cloneNext(index + 1, addPkgInfos ^& pkgInfos, repoPath ^& paths, errors)
diff --git a/src/config.nim b/src/config.nim
index fb1f3ae..ade174f 100644
--- a/src/config.nim
+++ b/src/config.nim
@@ -13,45 +13,50 @@ type
user = "User",
disabled = "Disabled"
- CommonConfig* = object of RootObj
- dbs*: seq[string]
- arch*: string
- debug*: bool
- progressBar*: bool
- verbosePkgList*: bool
- downloadTimeout*: bool
- pgpKeyserver*: Option[string]
- defaultRoot*: bool
- ignorePkgs*: HashSet[string]
- ignoreGroups*: HashSet[string]
-
- PacmanConfig* = object of CommonConfig
- sysrootOption*: Option[string]
- rootRelOption*: Option[string]
- dbRelOption*: Option[string]
- cacheRelOption*: Option[string]
- gpgRelOption*: Option[string]
- colorMode*: ColorMode
-
- Config* = object of CommonConfig
- root*: string
- db*: string
- cache*: string
- userCacheInitial*: string
- userCacheCurrent*: string
- tmpRootInitial*: string
- tmpRootCurrent*: string
- color*: bool
- aurRepo*: string
- aurComments*: bool
- checkIgnored*: bool
- ignoreArch*: bool
- printAurNotFound*: bool
- printLocalIsNewer*: bool
- sudoExec*: bool
- viewNoDefault*: bool
- preserveBuilt*: PreserveBuilt
- preBuildCommand*: Option[string]
+ CommonConfig* = tuple[
+ dbs: seq[string],
+ arch: string,
+ debug: bool,
+ progressBar: bool,
+ verbosePkgLists: bool,
+ downloadTimeout: bool,
+ pgpKeyserver: Option[string],
+ defaultRoot: bool,
+ ignorePkgs: HashSet[string],
+ ignoreGroups: HashSet[string]
+ ]
+
+ PacmanConfig* = tuple[
+ common: CommonConfig,
+ sysrootOption: Option[string],
+ rootRelOption: Option[string],
+ dbRelOption: Option[string],
+ cacheRelOption: Option[string],
+ gpgRelOption: Option[string],
+ colorMode: ColorMode
+ ]
+
+ Config* = tuple[
+ common: CommonConfig,
+ root: string,
+ db: string,
+ cache: string,
+ userCacheInitial: string,
+ userCacheCurrent: string,
+ tmpRootInitial: string,
+ tmpRootCurrent: string,
+ color: bool,
+ aurRepo: string,
+ aurComments: bool,
+ checkIgnored: bool,
+ ignoreArch: bool,
+ printAurNotFound: bool,
+ printLocalIsNewer: bool,
+ sudoExec: bool,
+ viewNoDefault: bool,
+ preserveBuilt: PreserveBuilt,
+ preBuildCommand: Option[string]
+ ]
proc readConfigFile*(configFile: string):
(OrderedTable[string, ref Table[string, string]], bool) =
@@ -93,7 +98,7 @@ proc readConfigFile*(configFile: string):
(table, wasError)
proc ignored*(config: Config, name: string, groups: openArray[string]): bool =
- name in config.ignorePkgs or (config.ignoreGroups * groups.toSet).len > 0
+ name in config.common.ignorePkgs or (config.common.ignoreGroups * groups.toSet).len > 0
proc get*(colorMode: ColorMode): bool =
case colorMode:
@@ -164,7 +169,7 @@ proc obtainConfig*(config: PacmanConfig): Config =
.optLast.get(PreserveBuilt.disabled)
let preBuildCommand = options.opt("PreBuildCommand")
- if config.dbs.find(aurRepo) >= 0:
+ if config.common.dbs.find(aurRepo) >= 0:
raise commandError(tr"repo '$#' can not be used as fake AUR repository" % [aurRepo],
colorNeeded = some(color))
@@ -172,19 +177,15 @@ proc obtainConfig*(config: PacmanConfig): Config =
raise commandError(trp("could not register '%s' database (%s)\n") %
[aurRepo, tra"wrong or NULL argument passed"], colorNeeded = some(color))
- Config(dbs: config.dbs, arch: config.arch, debug: config.debug,
- progressBar: config.progressBar, verbosePkgList: config.verbosePkgList,
- downloadTimeout: config.downloadTimeout, pgpKeyserver: config.pgpKeyserver,
- defaultRoot: config.defaultRoot and config.sysrootOption.isNone,
- ignorePkgs: config.ignorePkgs, ignoreGroups: config.ignoreGroups,
- root: root, db: db, cache: cache, userCacheInitial: userCacheInitial,
- userCacheCurrent: userCacheCurrent, tmpRootInitial: tmpRootInitial,
- tmpRootCurrent: tmpRootCurrent, color: color, aurRepo: aurRepo, aurComments: aurComments,
- checkIgnored: checkIgnored, ignoreArch: ignoreArch, printAurNotFound: printAurNotFound,
- printLocalIsNewer: printLocalIsNewer, sudoExec: sudoExec, viewNoDefault: viewNoDefault,
- preserveBuilt: preserveBuilt, preBuildCommand: preBuildCommand)
+ ((config.common.dbs, config.common.arch, config.common.debug, config.common.progressBar,
+ config.common.verbosePkgLists, config.common.downloadTimeout, config.common.pgpKeyserver,
+ config.common.defaultRoot and config.sysrootOption.isNone,
+ config.common.ignorePkgs, config.common.ignoreGroups),
+ root, db, cache, userCacheInitial, userCacheCurrent, tmpRootInitial, tmpRootCurrent,
+ color, aurRepo, aurComments, checkIgnored, ignoreArch, printAurNotFound, printLocalIsNewer,
+ sudoExec, viewNoDefault, preserveBuilt, preBuildCommand)
template withAlpmConfig*(config: Config, passDbs: bool,
handle: untyped, alpmDbs: untyped, errors: untyped, body: untyped): untyped =
- withAlpm(config.root, config.db, if passDbs: config.dbs else: @[], config.arch,
- handle, alpmDbs, errors, body)
+ withAlpm(config.root, config.db, if passDbs: config.common.dbs else: @[],
+ config.common.arch, handle, alpmDbs, errors, body)
diff --git a/src/feature/syncinfo.nim b/src/feature/syncinfo.nim
index f06cfa5..83f900b 100644
--- a/src/feature/syncinfo.nim
+++ b/src/feature/syncinfo.nim
@@ -109,7 +109,7 @@ proc handleSyncInfo*(args: seq[Argument], config: Config): int =
findSyncTargets(handle, dbs, targets, config.aurRepo, false, false)
let (pkgInfos, _, aerrors) = getAurPackageInfos(checkAurNames,
- config.aurRepo, config.arch, config.downloadTimeout)
+ config.aurRepo, config.common.arch, config.common.downloadTimeout)
for e in aerrors: printError(config.color, e)
let fullTargets = mapAurTargets[PackageInfo](syncTargets, pkgInfos, config.aurRepo)
diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim
index a5e9883..903dba1 100644
--- a/src/feature/syncinstall.nim
+++ b/src/feature/syncinstall.nim
@@ -41,7 +41,8 @@ proc groupsSeq(pkg: ptr AlpmPackage): seq[string] =
proc createCloneProgress(config: Config, count: int, flexible: bool, printMode: bool):
(proc (update: int, terminate: int) {.closure.}, proc {.closure.}) =
if count >= 1 and not printMode:
- let (update, terminate) = printProgressShare(config.progressBar, tr"cloning repositories")
+ let (update, terminate) = printProgressShare(config.common.progressBar,
+ tr"cloning repositories")
update(0, count)
if flexible:
@@ -207,12 +208,13 @@ proc findDependencies(config: Config, handle: ptr AlpmHandle, dbs: seq[ptr AlpmD
withAur():
let (pkgInfos, additionalPkgInfos, paths) = if printMode: (block:
let (pkgInfos, additionalPkgInfos, aerrors) = getAurPackageInfos(aurCheck
- .map(r => r.name), config.aurRepo, config.arch, config.downloadTimeout)
+ .map(r => r.name), config.aurRepo, config.common.arch,
+ config.common.downloadTimeout)
for e in aerrors: printError(config.color, e)
(pkgInfos, additionalPkgInfos, newSeq[string]()))
else: (block:
let (rpcInfos, aerrors) = getRpcPackageInfos(aurCheck.map(r => r.name),
- config.aurRepo, config.downloadTimeout)
+ config.aurRepo, config.common.downloadTimeout)
for e in aerrors: printError(config.color, e)
let (pkgInfos, additionalPkgInfos, paths, cerrors) =
cloneAurReposWithPackageInfos(config, rpcInfos, not printMode, update, true)
@@ -405,7 +407,7 @@ proc buildLoop(config: Config, pkgInfos: seq[PackageInfo], skipDeps: bool,
file.writeLine('#'.repeat(73))
file.writeLine("# PAKKU OVERRIDES")
file.writeLine('#'.repeat(73))
- file.writeLine("CARCH=" & config.arch.bashEscape)
+ file.writeLine("CARCH=" & config.common.arch.bashEscape)
file.writeLine("PKGDEST=" & config.tmpRootInitial.bashEscape)
finally:
file.close()
@@ -558,7 +560,7 @@ proc installGroupFromSources(config: Config, commonArgs: seq[Argument],
let (buildResults, buildCode) = buildNext(0, nil)
proc formatArchiveFile(pkgInfo: PackageInfo, ext: string): string =
- let arch = if pkgInfo.archs.len > 0: config.arch else: "any"
+ let arch = if pkgInfo.archs.len > 0: config.common.arch else: "any"
config.tmpRootInitial & "/" & pkgInfo.name & "-" & pkgInfo.version & "-" & arch & ext
let allFiles = lc[(r.name, formatArchiveFile(r.pkgInfo, br.ext)) |
@@ -649,7 +651,7 @@ proc installGroupFromSources(config: Config, commonArgs: seq[Argument],
template run(args: varargs[string]) =
discard forkWait(() => (block:
dropPrivilegesAndChdir(none(string)):
- if not config.debug:
+ if not config.common.debug:
discard close(1)
discard open("/dev/null")
discard close(2)
@@ -708,7 +710,7 @@ proc confirmViewAndImportKeys(config: Config, basePackages: seq[seq[seq[PackageI
if basePackages.len > 0: (block:
let installedVersions = installed.map(i => (i.name, i.version)).toTable
- printPackages(config.color, config.verbosePkgList,
+ printPackages(config.color, config.common.verbosePkgLists,
lc[(i.name, i.repo, installedVersions.opt(i.name), i.version) |
(g <- basePackages, b <- g, i <- b), PackageInstallFormat]
.sorted((a, b) => cmp(a.name, b.name)))
@@ -775,9 +777,9 @@ proc confirmViewAndImportKeys(config: Config, basePackages: seq[seq[seq[PackageI
if res == 'y' or newSkipKeys:
let importCode = forkWait(() => (block:
dropPrivilegesAndChdir(none(string)):
- if config.pgpKeyserver.isSome:
+ if config.common.pgpKeyserver.isSome:
forkWait(() => execResult(gpgCmd,
- "--keyserver", config.pgpKeyserver.unsafeGet,
+ "--keyserver", config.common.pgpKeyserver.unsafeGet,
"--recv-keys", pgpKeys[index]))
else:
forkWait(() => execResult(gpgCmd,
@@ -978,11 +980,11 @@ proc obtainAurPackageInfos(config: Config, rpcInfos: seq[RpcPackageInfo],
let (pkgInfos, additionalPkgInfos, paths, errors) = if printMode: (block:
let (pkgInfos, additionalPkgInfos, aerrors) = getAurPackageInfos(fullRpcInfos
- .map(i => i.name), config.aurRepo, config.arch, config.downloadTimeout)
+ .map(i => i.name), config.aurRepo, config.common.arch, config.common.downloadTimeout)
(pkgInfos, additionalPkgInfos, newSeq[string](), aerrors.deduplicate))
else: (block:
let (rpcInfos, aerrors) = getRpcPackageInfos(fullRpcInfos.map(i => i.name),
- config.aurRepo, config.downloadTimeout)
+ config.aurRepo, config.common.downloadTimeout)
let (pkgInfos, additionalPkgInfos, paths, cerrors) =
cloneAurReposWithPackageInfos(config, rpcInfos, not printMode, update, true)
(pkgInfos, additionalPkgInfos, paths, (toSeq(aerrors.items) & cerrors).deduplicate))
@@ -1067,7 +1069,7 @@ proc resolveBuildTargets(config: Config, syncTargets: seq[SyncPackageTarget],
if not printMode:
echo(tr"checking AUR database for upgrades...")
let (upgradeRpcInfos, rerrors) = getRpcPackageInfos(checkAurUpgradeNames,
- config.aurRepo, config.downloadTimeout)
+ config.aurRepo, config.common.downloadTimeout)
for e in rerrors: printError(config.color, e)
upgradeRpcInfos)
else:
@@ -1335,7 +1337,7 @@ proc resolveAurTargets(config: Config, targets: seq[PackageTarget], printMode: b
echo(tr"checking AUR database for targets...")
let (rpcInfos, rerrors) = getRpcPackageInfos(checkAurTargetNames,
- config.aurRepo, config.downloadTimeout)
+ config.aurRepo, config.common.downloadTimeout)
for e in rerrors: printError(config.color, e)
rpcInfos)
else:
diff --git a/src/feature/syncsearch.nim b/src/feature/syncsearch.nim
index 9aa179e..3d4cd0f 100644
--- a/src/feature/syncsearch.nim
+++ b/src/feature/syncsearch.nim
@@ -12,7 +12,7 @@ proc handleSyncSearch*(args: seq[Argument], config: Config): int =
let quiet = args.check(%%%"quiet")
let (aurPackages, aerrors) = findAurPackages(args.targets,
- config.aurRepo, config.downloadTimeout)
+ config.aurRepo, config.common.downloadTimeout)
for e in aerrors: printError(config.color, e)
type Package = tuple[rpcInfo: RpcPackageInfo, installedVersion: Option[string]]
diff --git a/src/feature/syncsource.nim b/src/feature/syncsource.nim
index e0531bc..b25d25d 100644
--- a/src/feature/syncsource.nim
+++ b/src/feature/syncsource.nim
@@ -134,7 +134,7 @@ proc cloneAndCopy(config: Config, quiet: bool,
let (update, terminate) = if quiet:
(proc (a: int, b: int) {.closure.} = discard, proc () {.closure.} = discard)
else:
- printProgressShare(config.progressBar, tr"cloning repositories")
+ printProgressShare(config.common.progressBar, tr"cloning repositories")
let (results, rerrors) = cloneRepositories(config, baseTargets, update)
terminate()
@@ -169,7 +169,7 @@ proc handleSyncSource*(args: seq[Argument], config: Config): int =
findSyncTargets(handle, dbs, targets, config.aurRepo, false, false)
let (rpcInfos, aerrors) = getRpcPackageInfos(checkAurNames,
- config.aurRepo, config.downloadTimeout)
+ config.aurRepo, config.common.downloadTimeout)
for e in aerrors: printError(config.color, e)
let notFoundTargets = filterNotFoundSyncTargets(syncTargets,
diff --git a/src/main.nim b/src/main.nim
index a149000..9508b33 100644
--- a/src/main.nim
+++ b/src/main.nim
@@ -99,7 +99,7 @@ proc handleSync(args: seq[Argument], config: Config): int =
if currentUser.uid != 0 and config.sudoExec and not printMode:
execSudo(args)
else:
- let isNonDefaultRoot = not config.defaultRoot
+ let isNonDefaultRoot = not config.common.defaultRoot
let isRootNoDrop = currentUser.uid == 0 and not canDropPrivileges()
let build = args.check(%%%"build")
diff --git a/src/pacman.nim b/src/pacman.nim
index 79ffe53..9ee692d 100644
--- a/src/pacman.nim
+++ b/src/pacman.nim
@@ -299,7 +299,7 @@ proc createConfigFromTable(table: Table[string, string], dbs: seq[string]): Pacm
let cacheRel = table.opt("CacheDir")
let gpgRel = table.opt("GPGDir")
let color = if table.hasKey("Color"): ColorMode.colorAuto else: ColorMode.colorNever
- let verbosePkgList = table.hasKey("VerbosePkgLists")
+ let verbosePkgLists = table.hasKey("VerbosePkgLists")
let downloadTimeout = not table.hasKey("DisableDownloadTimeout")
let arch = table.opt("Architecture").get("auto")
let ignorePkgs = table.opt("IgnorePkg").get("").splitWhitespace.toSet
@@ -310,11 +310,8 @@ proc createConfigFromTable(table: Table[string, string], dbs: seq[string]): Pacm
raise commandError(tr"can not get the architecture",
colorNeeded = some(color.get))
- PacmanConfig(sysrootOption: none(string), rootRelOption: rootRel,
- dbRelOption: dbRel, cacheRelOption: cacheRel, gpgRelOption: gpgRel,
- dbs: dbs, arch: archFinal, colorMode: color, debug: false, progressBar: true,
- verbosePkgList: verbosePkgList, downloadTimeout: downloadTimeout, pgpKeyserver: none(string),
- defaultRoot: true, ignorePkgs: ignorePkgs, ignoreGroups: ignoreGroups)
+ ((dbs, archFinal, false, true, verbosePkgLists, downloadTimeout, none(string), true,
+ ignorePkgs, ignoreGroups), none(string), rootRel, dbRel, cacheRel, gpgRel, color)
proc obtainPacmanConfig*(args: seq[Argument]): PacmanConfig =
proc getAll(pair: OptionPair): seq[string] =
@@ -343,7 +340,7 @@ proc obtainPacmanConfig*(args: seq[Argument]): PacmanConfig =
let dbRel = getAll(%%%"dbpath").optLast.orElse(defaultConfig.dbRelOption)
let cacheRel = getAll(%%%"cachedir").optLast.orElse(defaultConfig.cacheRelOption)
let gpgRel = getAll(%%%"gpgdir").optLast.orElse(defaultConfig.gpgRelOption)
- let arch = getAll(%%%"arch").optLast.get(defaultConfig.arch)
+ let arch = getAll(%%%"arch").optLast.get(defaultConfig.common.arch)
let colorStr = getAll(%%%"color").optLast.get($defaultConfig.colorMode)
let color = getColor(colorStr)
@@ -388,19 +385,16 @@ proc obtainPacmanConfig*(args: seq[Argument]): PacmanConfig =
let argsRootRel = rootRel.get("/")
let defaultRoot = defaultRootRel == argsRootRel
- let config = PacmanConfig(sysrootOption: sysroot, rootRelOption: rootRel,
- dbRelOption: dbRel, cacheRelOption: cacheRel, gpgRelOption: gpgRel,
- dbs: defaultConfig.dbs, arch: arch, colorMode: color, debug: debug,
- progressBar: progressBar, verbosePkgList: defaultConfig.verbosePkgList,
- downloadTimeout: defaultConfig.downloadTimeout and downloadTimeout,
- pgpKeyserver: pgpKeyserver, defaultRoot: defaultRoot,
- ignorePkgs: ignorePkgs + defaultConfig.ignorePkgs,
- ignoreGroups: ignoreGroups + defaultConfig.ignoreGroups)
+ let config: PacmanConfig = ((defaultConfig.common.dbs, arch, debug, progressBar,
+ defaultConfig.common.verbosePkgLists, defaultConfig.common.downloadTimeout and downloadTimeout,
+ pgpKeyserver, defaultRoot, ignorePkgs + defaultConfig.common.ignorePkgs,
+ ignoreGroups + defaultConfig.common.ignoreGroups),
+ sysroot, rootRel, dbRel, cacheRel, gpgRel, color)
pacmanValidateAndThrow((("sysroot", sysroot, ArgumentType.long), sysroot.isSome),
(("root", some(config.pacmanRootRel), ArgumentType.long), not defaultRoot),
(("dbpath", some(config.pacmanDbRel), ArgumentType.long), true),
- (("arch", some(config.arch), ArgumentType.long), true),
+ (("arch", some(config.common.arch), ArgumentType.long), true),
(("color", some(colorStr), ArgumentType.long), true))
config