aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkitsunyan2018-06-09 19:26:16 +0000
committerkitsunyan2018-06-09 19:26:16 +0000
commit0b6c3e6732c5c0d5b6613d2fe450c3b7760c0827 (patch)
tree72fac7f0d47d7ef1683bc2be639fb3cea524ee17 /src
parent56e82963b465116af32231aa531e8f6344826eab (diff)
Add support for "--disable-download-timeout" option
Diffstat (limited to 'src')
-rw-r--r--src/aur.nim22
-rw-r--r--src/config.nim6
-rw-r--r--src/feature/syncinfo.nim3
-rw-r--r--src/feature/syncinstall.nim16
-rw-r--r--src/feature/syncsearch.nim3
-rw-r--r--src/feature/syncsource.nim3
-rw-r--r--src/pacman.nim8
-rw-r--r--src/wrapper/curl.nim11
8 files changed, 43 insertions, 29 deletions
diff --git a/src/aur.nim b/src/aur.nim
index f86600f..d74d08a 100644
--- a/src/aur.nim
+++ b/src/aur.nim
@@ -44,17 +44,18 @@ template withAur*(body: untyped): untyped =
withCurlGlobal():
body
-proc obtainPkgBaseSrcInfo(base: string): (string, Option[string]) =
+proc obtainPkgBaseSrcInfo(base: string, useTimeout: bool): (string, Option[string]) =
try:
withAur():
withCurl(instance):
let url = aurUrl & "cgit/aur.git/plain/.SRCINFO?h=" &
instance.escape(base)
- (performString(url), none(string))
+ (performString(url, useTimeout), none(string))
except CurlError:
("", some(getCurrentException().msg))
-proc getRpcPackageInfos*(pkgs: seq[string], repo: string): (seq[RpcPackageInfo], Option[string]) =
+proc getRpcPackageInfos*(pkgs: seq[string], repo: string, useTimeout: bool):
+ (seq[RpcPackageInfo], Option[string]) =
if pkgs.len == 0:
(@[], none(string))
else:
@@ -66,7 +67,7 @@ proc getRpcPackageInfos*(pkgs: seq[string], repo: string): (seq[RpcPackageInfo],
.map(u => instance.escape(u))
.foldl(a & "&arg[]=" & b)
- let response = performString(url)
+ let response = performString(url, useTimeout)
let results = parseJson(response)["results"]
let table = lc[(x.name, x) | (y <- results, x <- parseRpcPackageInfo(y, repo)),
(string, RpcPackageInfo)].toTable
@@ -76,13 +77,13 @@ proc getRpcPackageInfos*(pkgs: seq[string], repo: string): (seq[RpcPackageInfo],
except JsonParsingError:
(@[], some(tr"failed to parse server response"))
-proc getAurPackageInfos*(pkgs: seq[string], repo: string, arch: string):
+proc getAurPackageInfos*(pkgs: seq[string], repo: string, arch: string, useTimeout: bool):
(seq[PackageInfo], seq[PackageInfo], seq[string]) =
if pkgs.len == 0:
(@[], @[], @[])
else:
withAur():
- let (rpcInfos, error) = getRpcPackageInfos(pkgs, repo)
+ let (rpcInfos, error) = getRpcPackageInfos(pkgs, repo, useTimeout)
if error.isSome:
(@[], @[], @[error.unsafeGet])
@@ -96,7 +97,7 @@ proc getAurPackageInfos*(pkgs: seq[string], repo: string, arch: string):
let deduplicated = lc[x.base | (x <- rpcInfos), string].deduplicate
proc obtainAndParse(base: string, index: int): ParseResult =
- let (srcInfo, operror) = obtainPkgBaseSrcInfo(base)
+ let (srcInfo, operror) = obtainPkgBaseSrcInfo(base, useTimeout)
if operror.isSome:
(@[], operror)
@@ -117,7 +118,8 @@ proc getAurPackageInfos*(pkgs: seq[string], repo: string, arch: string):
(pkgInfos, additionalPkgInfos, errors)
-proc findAurPackages*(query: seq[string], repo: string): (seq[RpcPackageInfo], Option[string]) =
+proc findAurPackages*(query: seq[string], repo: string, useTimeout: bool):
+ (seq[RpcPackageInfo], Option[string]) =
if query.len == 0 or query[0].len <= 2:
(@[], none(string))
else:
@@ -127,7 +129,7 @@ proc findAurPackages*(query: seq[string], repo: string): (seq[RpcPackageInfo], O
let url = aurUrl & "rpc/?v=5&type=search&by=name&arg=" &
instance.escape(query[0])
- let response = performString(url)
+ let response = performString(url, useTimeout)
let results = parseJson(response)["results"]
let rpcInfos = lc[x | (y <- results, x <- parseRpcPackageInfo(y, repo)), RpcPackageInfo]
@@ -147,7 +149,7 @@ proc downloadAurComments*(base: string): (seq[AurComment], Option[string]) =
try:
withCurl(instance):
let url = aurUrl & "pkgbase/" & base & "/?comments=all"
- (performString(url), none(string))
+ (performString(url, true), none(string))
except CurlError:
("", some(getCurrentException().msg))
diff --git a/src/config.nim b/src/config.nim
index 7daaa53..a0c8281 100644
--- a/src/config.nim
+++ b/src/config.nim
@@ -19,6 +19,7 @@ type
debug*: bool
progressBar*: bool
verbosePkgList*: bool
+ downloadTimeout*: bool
pgpKeyserver*: Option[string]
defaultRoot*: bool
ignorePkgs*: HashSet[string]
@@ -167,8 +168,9 @@ 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, pgpKeyserver: config.pgpKeyserver,
+ 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,
diff --git a/src/feature/syncinfo.nim b/src/feature/syncinfo.nim
index 483df3c..546c631 100644
--- a/src/feature/syncinfo.nim
+++ b/src/feature/syncinfo.nim
@@ -110,7 +110,8 @@ proc handleSyncInfo*(args: seq[Argument], config: Config): int =
for e in errors: printError(config.color, e)
findSyncTargets(handle, dbs, targets, config.aurRepo, false, false)
- let (pkgInfos, _, aerrors) = getAurPackageInfos(checkAurNames, config.aurRepo, config.arch)
+ let (pkgInfos, _, aerrors) = getAurPackageInfos(checkAurNames,
+ config.aurRepo, config.arch, config.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 b583fe6..7b5bd5d 100644
--- a/src/feature/syncinstall.nim
+++ b/src/feature/syncinstall.nim
@@ -199,13 +199,13 @@ proc findDependencies(config: Config, handle: ptr AlpmHandle, dbs: seq[ptr AlpmD
try:
withAur():
let (pkgInfos, additionalPkgInfos, paths) = if printMode: (block:
- let (pkgInfos, additionalPkgInfos, aerrors) =
- getAurPackageInfos(aurCheck.map(r => r.name), config.aurRepo, config.arch)
+ let (pkgInfos, additionalPkgInfos, aerrors) = getAurPackageInfos(aurCheck
+ .map(r => r.name), config.aurRepo, config.arch, config.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.aurRepo, config.downloadTimeout)
for e in aerrors: printError(config.color, e)
let (pkgInfos, additionalPkgInfos, paths, cerrors) =
cloneAurReposWithPackageInfos(config, rpcInfos, not printMode, update, true)
@@ -1135,11 +1135,12 @@ proc obtainAurPackageInfos(config: Config, rpcInfos: seq[RpcPackageInfo],
let (update, terminate) = createCloneProgress(config, fullRpcInfos.len, true, printMode)
let (pkgInfos, additionalPkgInfos, paths, errors) = if printMode: (block:
- let (pkgInfos, additionalPkgInfos, aerrors) =
- getAurPackageInfos(fullRpcInfos.map(i => i.name), config.aurRepo, config.arch)
+ let (pkgInfos, additionalPkgInfos, aerrors) = getAurPackageInfos(fullRpcInfos
+ .map(i => i.name), config.aurRepo, config.arch, config.downloadTimeout)
(pkgInfos, additionalPkgInfos, newSeq[string](), aerrors.deduplicate))
else: (block:
- let (rpcInfos, aerrors) = getRpcPackageInfos(fullRpcInfos.map(i => i.name), config.aurRepo)
+ let (rpcInfos, aerrors) = getRpcPackageInfos(fullRpcInfos.map(i => i.name),
+ config.aurRepo, config.downloadTimeout)
let (pkgInfos, additionalPkgInfos, paths, cerrors) =
cloneAurReposWithPackageInfos(config, rpcInfos, not printMode, update, true)
(pkgInfos, additionalPkgInfos, paths, (toSeq(aerrors.items) & cerrors).deduplicate))
@@ -1248,7 +1249,8 @@ proc resolveBuildTargets(config: Config, targets: seq[PackageTarget],
if checkAurNames.len > 0:
echo(tr"checking AUR database...")
- let (rpcInfos, rerrors) = getRpcPackageInfos(checkAurNames, config.aurRepo)
+ let (rpcInfos, rerrors) = getRpcPackageInfos(checkAurNames,
+ config.aurRepo, config.downloadTimeout)
for e in rerrors: printError(config.color, e)
let rpcNotFoundTargets = filterNotFoundSyncTargets(syncTargets,
diff --git a/src/feature/syncsearch.nim b/src/feature/syncsearch.nim
index 7a9199d..9aa179e 100644
--- a/src/feature/syncsearch.nim
+++ b/src/feature/syncsearch.nim
@@ -11,7 +11,8 @@ proc handleSyncSearch*(args: seq[Argument], config: Config): int =
else:
let quiet = args.check(%%%"quiet")
- let (aurPackages, aerrors) = findAurPackages(args.targets, config.aurRepo)
+ let (aurPackages, aerrors) = findAurPackages(args.targets,
+ config.aurRepo, config.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 df543c7..e0531bc 100644
--- a/src/feature/syncsource.nim
+++ b/src/feature/syncsource.nim
@@ -168,7 +168,8 @@ proc handleSyncSource*(args: seq[Argument], config: Config): int =
for e in errors: printError(config.color, e)
findSyncTargets(handle, dbs, targets, config.aurRepo, false, false)
- let (rpcInfos, aerrors) = getRpcPackageInfos(checkAurNames, config.aurRepo)
+ let (rpcInfos, aerrors) = getRpcPackageInfos(checkAurNames,
+ config.aurRepo, config.downloadTimeout)
for e in aerrors: printError(config.color, e)
let notFoundTargets = filterNotFoundSyncTargets(syncTargets,
diff --git a/src/pacman.nim b/src/pacman.nim
index 7303eec..79ffe53 100644
--- a/src/pacman.nim
+++ b/src/pacman.nim
@@ -79,6 +79,7 @@ const
^o("color"),
^o("config"),
o("debug"),
+ o("disable-download-timeout"),
^o("gpgdir"),
^o("hookdir"),
^o("logfile"),
@@ -299,6 +300,7 @@ proc createConfigFromTable(table: Table[string, string], dbs: seq[string]): Pacm
let gpgRel = table.opt("GPGDir")
let color = if table.hasKey("Color"): ColorMode.colorAuto else: ColorMode.colorNever
let verbosePkgList = table.hasKey("VerbosePkgLists")
+ let downloadTimeout = not table.hasKey("DisableDownloadTimeout")
let arch = table.opt("Architecture").get("auto")
let ignorePkgs = table.opt("IgnorePkg").get("").splitWhitespace.toSet
let ignoreGroups = table.opt("IgnoreGroup").get("").splitWhitespace.toSet
@@ -311,8 +313,8 @@ proc createConfigFromTable(table: Table[string, string], dbs: seq[string]): Pacm
PacmanConfig(sysrootOption: none(string), rootRelOption: rootRel,
dbRelOption: dbRel, cacheRelOption: cacheRel, gpgRelOption: gpgRel,
dbs: dbs, arch: archFinal, colorMode: color, debug: false, progressBar: true,
- verbosePkgList: verbosePkgList, pgpKeyserver: none(string), defaultRoot: true,
- ignorePkgs: ignorePkgs, ignoreGroups: ignoreGroups)
+ verbosePkgList: verbosePkgList, downloadTimeout: downloadTimeout, pgpKeyserver: none(string),
+ defaultRoot: true, ignorePkgs: ignorePkgs, ignoreGroups: ignoreGroups)
proc obtainPacmanConfig*(args: seq[Argument]): PacmanConfig =
proc getAll(pair: OptionPair): seq[string] =
@@ -336,6 +338,7 @@ proc obtainPacmanConfig*(args: seq[Argument]): PacmanConfig =
let colors = toSeq(enumerate[ColorMode]())
colors.filter(c => $c == color).optLast.get(ColorMode.colorNever)
+ let downloadTimeout = not args.check(%%%"disable-download-timeout")
let rootRel = getAll(%%%"root").optLast.orElse(defaultConfig.rootRelOption)
let dbRel = getAll(%%%"dbpath").optLast.orElse(defaultConfig.dbRelOption)
let cacheRel = getAll(%%%"cachedir").optLast.orElse(defaultConfig.cacheRelOption)
@@ -389,6 +392,7 @@ proc obtainPacmanConfig*(args: seq[Argument]): PacmanConfig =
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)
diff --git a/src/wrapper/curl.nim b/src/wrapper/curl.nim
index 5f3e814..98d6880 100644
--- a/src/wrapper/curl.nim
+++ b/src/wrapper/curl.nim
@@ -99,19 +99,20 @@ template withCurl*(instance: untyped, body: untyped): untyped =
else:
raise newException(CurlError, tr"failed to perform request")
- proc performInternal(url: string): seq[char] =
+ proc performInternal(url: string, useTimeout: bool): seq[char] =
+ let timeoutMs = if useTimeout: 15000 else: 0
raiseError(handle.setOption(CurlOption.followLocation, (clong) 1))
raiseError(handle.setOption(CurlOption.noSignal, (clong) 1))
- raiseError(handle.setOption(CurlOption.timeoutMs, (clong) 15000))
- raiseError(handle.setOption(CurlOption.connectTimeoutMs, (clong) 15000))
+ raiseError(handle.setOption(CurlOption.timeoutMs, (clong) timeoutMs))
+ raiseError(handle.setOption(CurlOption.connectTimeoutMs, (clong) timeoutMs))
raiseError(handle.setOption(CurlOption.url, url))
raiseError(handle.setOption(CurlOption.writeFunction, cast[pointer](curlWriteMemory)))
raiseError(handle.setOption(CurlOption.writeData, instance))
raiseError(handle.perform())
instance.data
- proc performString(url: string): string =
- let data = performInternal(url)
+ proc performString(url: string, useTimeout: bool): string =
+ let data = performInternal(url, useTimeout)
var str = newStringOfCap(data.len)
for c in data:
str.add(c)