diff options
-rw-r--r-- | src/common.nim | 66 | ||||
-rw-r--r-- | src/feature/syncinfo.nim | 16 | ||||
-rw-r--r-- | src/feature/syncinstall.nim | 6 |
3 files changed, 45 insertions, 43 deletions
diff --git a/src/common.nim b/src/common.nim index 9288d64..f45472d 100644 --- a/src/common.nim +++ b/src/common.nim @@ -20,7 +20,7 @@ type repo*: Option[string] SyncPackageTarget* = object of PackageTarget - foundInfo*: Option[SyncFoundInfo] + foundInfos*: seq[SyncFoundInfo] FullPackageTarget*[T] = object of SyncPackageTarget pkgInfo*: Option[T] @@ -62,10 +62,10 @@ proc packageTargets*(args: seq[Argument]): seq[PackageTarget] = PackageTarget(reference: reference, repo: repo))) proc isAurTargetSync*(target: SyncPackageTarget): bool = - target.foundInfo.isNone and (target.repo.isNone or target.repo == some("aur")) + target.foundInfos.len == 0 and (target.repo.isNone or target.repo == some("aur")) proc isAurTargetFull*[T: RpcPackageInfo](target: FullPackageTarget[T]): bool = - target.foundInfo.isSome and target.foundInfo.unsafeGet.repo == "aur" + target.foundInfos.len > 0 and target.foundInfos[0].repo == "aur" proc findSyncTargets*(handle: ptr AlpmHandle, dbs: seq[ptr AlpmDatabase], targets: seq[PackageTarget], allowGroups: bool, checkProvides: bool): @@ -79,7 +79,7 @@ proc findSyncTargets*(handle: ptr AlpmHandle, dbs: seq[ptr AlpmDatabase], return true return false - proc findSync(target: PackageTarget): Option[SyncFoundInfo] = + proc findSync(target: PackageTarget): seq[SyncFoundInfo] = if target.repo.isSome: let repo = target.repo.unsafeGet @@ -89,15 +89,21 @@ proc findSyncTargets*(handle: ptr AlpmHandle, dbs: seq[ptr AlpmDatabase], if pkg != nil and target.reference.isProvidedBy(pkg.toPackageReference): let base = if pkg.base == nil: target.reference.name else: $pkg.base - return some((repo, some((base, $pkg.version, some($pkg.arch))))) + return @[(repo, some((base, $pkg.version, some($pkg.arch))))] elif checkProvides and target.reference.checkProvided(db): - return some((repo, none(SyncFoundPackageInfo))) + return @[(repo, none(SyncFoundPackageInfo))] else: - return none(SyncFoundInfo) + return @[] else: - return none(SyncFoundInfo) + return @[] else: - let directResult = dbs + if allowGroups and target.reference.constraint.isNone: + let groupRepo = lc[d | (d <- dbs, g <- d.groups, + $g.name == target.reference.name), ptr AlpmDatabase].optFirst + if groupRepo.isSome: + return @[($groupRepo.unsafeGet.name, none(SyncFoundPackageInfo))] + + let directResults = dbs .map(db => (block: let pkg = db[target.reference.name] if pkg != nil and target.reference.isProvidedBy(pkg.toPackageReference): @@ -106,28 +112,20 @@ proc findSyncTargets*(handle: ptr AlpmHandle, dbs: seq[ptr AlpmDatabase], else: none(SyncFoundInfo))) .filter(i => i.isSome) - .optFirst - .flatten - - if directResult.isSome: - return directResult + .map(i => i.unsafeGet) + + if directResults.len > 0: + return directResults + elif checkProvides: + for db in dbs: + if target.reference.checkProvided(db): + return @[($db.name, none(SyncFoundPackageInfo))] + return @[] else: - if allowGroups and target.reference.constraint.isNone: - let groupRepo = lc[d | (d <- dbs, g <- d.groups, - $g.name == target.reference.name), ptr AlpmDatabase].optFirst - if groupRepo.isSome: - return groupRepo.map(d => ($d.name, none(SyncFoundPackageInfo))) - - if checkProvides: - for db in dbs: - if target.reference.checkProvided(db): - return some(($db.name, none(SyncFoundPackageInfo))) - return none(SyncFoundInfo) - else: - return none(SyncFoundInfo) + return @[] let syncTargets = targets.map(t => SyncPackageTarget(reference: t.reference, - repo: t.repo, foundInfo: findSync(t))) + repo: t.repo, foundInfos: findSync(t))) let checkAurNames = syncTargets.filter(isAurTargetSync).map(t => t.reference.name) (syncTargets, checkAurNames) @@ -136,7 +134,7 @@ proc mapAurTargets*[T: RpcPackageInfo](targets: seq[SyncPackageTarget], let aurTable = pkgInfos.map(i => (i.name, i)).toTable targets.map(proc (target: SyncPackageTarget): FullPackageTarget[T] = - let res = if target.foundInfo.isNone and aurTable.hasKey(target.reference.name): (block: + let res = if target.foundInfos.len == 0 and aurTable.hasKey(target.reference.name): (block: let pkgInfo = aurTable[target.reference.name] if target.reference.isProvidedBy(pkgInfo.toPackageReference): some((("aur", some((pkgInfo.base, pkgInfo.version, none(string)))), pkgInfo)) @@ -148,10 +146,10 @@ proc mapAurTargets*[T: RpcPackageInfo](targets: seq[SyncPackageTarget], if res.isSome: let (syncInfo, pkgInfo) = res.get FullPackageTarget[T](reference: target.reference, repo: target.repo, - foundInfo: some(syncInfo), pkgInfo: some(pkgInfo)) + foundInfos: @[syncInfo], pkgInfo: some(pkgInfo)) else: FullPackageTarget[T](reference: target.reference, repo: target.repo, - foundInfo: target.foundInfo, pkgInfo: none(T))) + foundInfos: target.foundInfos, pkgInfo: none(T))) proc queryUnrequired*(handle: ptr AlpmHandle, withOptional: bool, withoutOptional: bool, assumeExplicit: HashSet[string]): (HashSet[string], HashSet[string], HashSet[string]) = @@ -212,8 +210,8 @@ proc queryUnrequired*(handle: ptr AlpmHandle, withOptional: bool, withoutOptiona (installed, withOptionalSet, withoutOptionalSet) -proc formatArgument*(target: PackageTarget): string = - target.repo.map(r => r & "/" & $target.reference).get($target.reference) +proc `$`*[T: PackageTarget](target: T): string = + target.repo.map(proc (r: string): string = r & "/" & $target.reference).get($target.reference) proc ensureTmpOrError*(config: Config): Option[string] = let tmpRootExists = try: @@ -413,7 +411,7 @@ proc obtainBuildPkgInfos*[T: RpcPackageInfo](config: Config, pacmanTargets: seq[FullPackageTarget[T]]): (seq[PackageInfo], seq[string]) = let bases = pacmanTargets .map(proc (target: FullPackageTarget[T]): LookupBaseGroup = - let info = target.foundInfo.get + let info = target.foundInfos[0] let pkg = info.pkg.get (pkg.base, pkg.version, pkg.arch.get, info.repo)) .deduplicate diff --git a/src/feature/syncinfo.nim b/src/feature/syncinfo.nim index d00dcc0..30f6f20 100644 --- a/src/feature/syncinfo.nim +++ b/src/feature/syncinfo.nim @@ -61,7 +61,7 @@ proc formatDate(date: Option[int64]): seq[string] = proc handleTarget(config: Config, padding: int, args: seq[Argument], target: FullPackageTarget[PackageInfo]): int = - if target.foundInfo.isSome: + if target.foundInfos.len > 0: if isAurTargetFull[PackageInfo](target): let pkgInfo = target.pkgInfo.unsafeGet @@ -85,16 +85,19 @@ proc handleTarget(config: Config, padding: int, args: seq[Argument], (tr"Rating", @[formatPkgRating(pkgInfo.votes, pkgInfo.popularity)], false)) 0 + elif target.reference.constraint.isSome: + # pacman doesn't support constraints for --info queries + pacmanRun(false, config.color, args & target.foundInfos.map(i => + (i.repo & "/" & target.reference.name, none(string), ArgumentType.target))) else: pacmanRun(false, config.color, args & - (target.formatArgument, none(string), ArgumentType.target)) + ($target, none(string), ArgumentType.target)) else: if target.repo == some("aur"): - printError(config.color, trp("package '%s' was not found\n") % [target.formatArgument]) + printError(config.color, trp("package '%s' was not found\n") % [$target]) 1 else: - pacmanRun(false, config.color, args & - (target.formatArgument, none(string), ArgumentType.target)) + pacmanRun(false, config.color, args & ($target, none(string), ArgumentType.target)) proc handleSyncInfo*(args: seq[Argument], config: Config): int = let (_, callArgs) = checkAndRefresh(config.color, args) @@ -112,7 +115,8 @@ proc handleSyncInfo*(args: seq[Argument], config: Config): int = let fullTargets = mapAurTargets[PackageInfo](syncTargets, pkgInfos) let code = min(aerrors.len, 1) - if fullTargets.filter(isAurTargetFull[PackageInfo]).len == 0: + 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) else: diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim index 163bf34..ecca6ef 100644 --- a/src/feature/syncinstall.nim +++ b/src/feature/syncinstall.nim @@ -211,7 +211,7 @@ proc filterNotFoundSyncTargetsInternal(syncTargets: seq[SyncPackageTarget], upToDateNeededTable: Table[string, PackageReference]): seq[SyncPackageTarget] = # collect packages which were found neither in sync DB nor in AUR syncTargets.filter(t => not (upToDateNeededTable.opt(t.reference.name) - .map(r => t.reference.isProvidedBy(r)).get(false)) and t.foundInfo.isNone and + .map(r => t.reference.isProvidedBy(r)).get(false)) and t.foundInfos.len == 0 and not (t.isAurTargetSync and pkgInfoReferencesTable.opt(t.reference.name) .map(r => t.reference.isProvidedBy(r)).get(false))) @@ -1071,7 +1071,7 @@ proc handleSyncInstall*(args: seq[Argument], config: Config): int = let neededPacmanTargets = if printFormat.isNone and build and needed: pacmanTargets.filter(target => (block: - let version = target.foundInfo.get.pkg.get.version + let version = target.foundInfos[0].pkg.get.version if installedTable.checkNeeded(target.reference.name, version, true).needed: true else: @@ -1138,7 +1138,7 @@ proc handleSyncInstall*(args: seq[Argument], config: Config): int = let fullPkgInfos = finalPkgInfos & lc[i | (s <- satisfied.values, i <- s.buildPkgInfo, not (i.name in buildAndAurTargetSet)), PackageInfo].deduplicate - let directPacmanTargets = pacmanTargets.map(t => t.formatArgument) + let directPacmanTargets = pacmanTargets.map(`$`) let additionalPacmanTargets = lc[x.name | (x <- satisfied.values, not x.installed and x.buildPkgInfo.isNone), string] let orderedPkgInfos = orderInstallation(fullPkgInfos, satisfied) |