From 1b3cca2815e8d8c3aa3fa11ed6cdccd7eae0421e Mon Sep 17 00:00:00 2001 From: kitsunyan Date: Sat, 2 Jun 2018 15:18:38 +0300 Subject: Abort sync operation if "--refresh" fails --- src/feature/syncinfo.nim | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'src/feature/syncinfo.nim') diff --git a/src/feature/syncinfo.nim b/src/feature/syncinfo.nim index fc1510b..2de5bda 100644 --- a/src/feature/syncinfo.nim +++ b/src/feature/syncinfo.nim @@ -100,29 +100,32 @@ proc handleTarget(config: Config, padding: int, args: seq[Argument], pacmanRun(false, config.color, args & ($target, none(string), ArgumentType.target)) proc handleSyncInfo*(args: seq[Argument], config: Config): int = - let (_, callArgs) = checkAndRefresh(config.color, args) - let targets = args.packageTargets(false) + let (refreshCode, callArgs) = checkAndRefresh(config.color, args) + if refreshCode != 0: + refreshCode + else: + let targets = args.packageTargets(false) - let (syncTargets, checkAurNames) = withAlpmConfig(config, true, handle, dbs, errors): - for e in errors: printError(config.color, e) - findSyncTargets(handle, dbs, targets, false, false) + let (syncTargets, checkAurNames) = withAlpmConfig(config, true, handle, dbs, errors): + for e in errors: printError(config.color, e) + findSyncTargets(handle, dbs, targets, false, false) - let (pkgInfos, _, aerrors) = getAurPackageInfos(checkAurNames, config.arch) - for e in aerrors: printError(config.color, e) + let (pkgInfos, _, aerrors) = getAurPackageInfos(checkAurNames, config.arch) + for e in aerrors: printError(config.color, e) - let fullTargets = mapAurTargets[PackageInfo](syncTargets, pkgInfos) + let fullTargets = mapAurTargets[PackageInfo](syncTargets, pkgInfos) - let code = min(aerrors.len, 1) - if fullTargets.filter(t => isAurTargetFull[PackageInfo](t) or t.repo == some("aur")).len == 0 and - fullTargets.filter(t => t.reference.constraint.isSome).len == 0: - if code == 0: - pacmanExec(false, config.color, callArgs) + let code = min(aerrors.len, 1) + if fullTargets.filter(t => isAurTargetFull[PackageInfo](t) or t.repo == some("aur") or + t.reference.constraint.isSome).len == 0: + if code == 0: + pacmanExec(false, config.color, callArgs) + else: + discard pacmanRun(false, config.color, callArgs) + code else: - discard pacmanRun(false, config.color, callArgs) - code - else: - let finalArgs = callArgs.filter(arg => not arg.isTarget) - let padding = pacmanInfoStrings.map(s => s.trp).computeMaxLength + let finalArgs = callArgs.filter(arg => not arg.isTarget) + let padding = pacmanInfoStrings.map(s => s.trp).computeMaxLength - let codes = code & lc[handleTarget(config, padding, finalArgs, x) | (x <- fullTargets), int] - codes.filter(c => c != 0).optFirst.get(0) + let codes = code & lc[handleTarget(config, padding, finalArgs, x) | (x <- fullTargets), int] + codes.filter(c => c != 0).optFirst.get(0) -- cgit v1.2.3-70-g09d2