aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common.nim17
-rw-r--r--src/feature/localquery.nim20
-rw-r--r--src/feature/syncinstall.nim8
-rw-r--r--src/package.nim11
4 files changed, 36 insertions, 20 deletions
diff --git a/src/common.nim b/src/common.nim
index 8518ded..1749ed7 100644
--- a/src/common.nim
+++ b/src/common.nim
@@ -187,8 +187,10 @@ proc mapAurTargets*[T: RpcPackageInfo](targets: seq[SyncPackageTarget],
destination: target.destination, foundInfos: target.foundInfos, pkgInfo: none(T)))
proc queryUnrequired*(handle: ptr AlpmHandle, withOptional: bool, withoutOptional: bool,
- assumeExplicit: HashSet[string]): (HashSet[string], HashSet[string], HashSet[string]) =
- let (explicit, dependsTable, alternatives) = block:
+ assumeExplicit: HashSet[string]): (seq[PackageReference], HashSet[string], HashSet[string],
+ Table[string, HashSet[PackageReference]]) =
+ let (installed, explicit, dependsTable, alternatives) = block:
+ var installed = newSeq[PackageReference]()
var explicit = newSeq[string]()
var dependsTable = initTable[string,
HashSet[tuple[reference: PackageReference, optional: bool]]]()
@@ -198,7 +200,7 @@ proc queryUnrequired*(handle: ptr AlpmHandle, withOptional: bool, withoutOptiona
proc fixProvides(reference: PackageReference): PackageReference =
if reference.constraint.isNone:
(reference.name, reference.description,
- some((ConstraintOperation.eq, $pkg.version)))
+ some((ConstraintOperation.eq, $pkg.version, true)))
else:
reference
@@ -209,6 +211,7 @@ proc queryUnrequired*(handle: ptr AlpmHandle, withOptional: bool, withoutOptiona
let provides = toSeq(pkg.provides.items)
.map(d => d.toPackageReference).map(fixProvides).toSet
+ installed.add(pkg.toPackageReference)
if pkg.reason == AlpmReason.explicit:
explicit &= $pkg.name
dependsTable.add($pkg.name,
@@ -216,7 +219,7 @@ proc queryUnrequired*(handle: ptr AlpmHandle, withOptional: bool, withoutOptiona
if provides.len > 0:
alternatives.add($pkg.name, provides)
- (explicit.toSet + assumeExplicit, dependsTable, alternatives)
+ (installed, explicit.toSet + assumeExplicit, dependsTable, alternatives)
let providedBy = lc[(y, x.key) | (x <- alternatives.namedPairs, y <- x.value),
tuple[reference: PackageReference, name: string]]
@@ -234,16 +237,16 @@ proc queryUnrequired*(handle: ptr AlpmHandle, withOptional: bool, withoutOptiona
let checkNext = (direct.map(p => p.name).toSet + indirect) - full
if checkNext.len > 0: findRequired(withOptional, full, checkNext) else: full
- let installed = toSeq(dependsTable.keys).toSet
+ let installedNames = installed.map(i => i.name).toSet
proc findOrphans(withOptional: bool): HashSet[string] =
let required = findRequired(withOptional, initSet[string](), explicit)
- installed - required
+ installedNames - required
let withOptionalSet = if withOptional: findOrphans(true) else: initSet[string]()
let withoutOptionalSet = if withoutOptional: findOrphans(false) else: initSet[string]()
- (installed, withOptionalSet, withoutOptionalSet)
+ (installed, withOptionalSet, withoutOptionalSet, alternatives)
proc `$`*[T: PackageTarget](target: T): string =
target.repo.map(proc (r: string): string = r & "/" & $target.reference).get($target.reference)
diff --git a/src/feature/localquery.nim b/src/feature/localquery.nim
index f8436cd..4a21fa9 100644
--- a/src/feature/localquery.nim
+++ b/src/feature/localquery.nim
@@ -4,16 +4,28 @@ import
"../wrapper/alpm"
proc handleQueryOrphans*(args: seq[Argument], config: Config): int =
- let (installed, orphans, _) = withAlpmConfig(config, false, handle, dbs, errors):
+ let (installed, orphans, _, alternatives) = withAlpmConfig(config, false, handle, dbs, errors):
for e in errors: printError(config.color, e)
queryUnrequired(handle, true, false, initSet[string]())
- let targets = args.targets.map(t => (if t[0 .. 5] == "local/": t[6 .. ^1] else: t))
+ let targets = args.packageTargets(false)
+
+ proc isOrphanOrNotFound(reference: PackageReference): bool =
+ for r in installed:
+ if reference.isProvidedBy(r, true):
+ return reference.name in orphans
+ for name, references in alternatives:
+ for r in references:
+ let hasConstraint = r.constraint.isSome and not r.constraint.unsafeGet.impliedVersion
+ if (not hasConstraint and reference.constraint.isNone and r.name == reference.name) or
+ (hasConstraint and reference.isProvidedBy(r, true)):
+ return name in orphans
+ return true
# Provide similar output for not installed packages
- let unknownTargets = targets.toSet - installed
let results = if targets.len > 0:
- targets.filter(t => t in orphans or t in unknownTargets)
+ targets.filter(t => (t.repo.isNone or t.repo == some("local")) and
+ t.reference.isOrphanOrNotFound).map(t => $t)
else:
toSeq(orphans.items).sorted(cmp)
diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim
index 6f23eee..4bb3837 100644
--- a/src/feature/syncinstall.nim
+++ b/src/feature/syncinstall.nim
@@ -860,7 +860,7 @@ proc handleInstall(args: seq[Argument], config: Config, upgradeCount: int, nodep
clearPaths(paths)
confirmAndResolveCode
else:
- let (_, initialUnrequired, initialUnrequiredWithoutOptional) =
+ let (_, initialUnrequired, initialUnrequiredWithoutOptional, _) =
withAlpmConfig(config, false, handle, dbs, errors):
queryUnrequired(handle, true, true, keepNames)
@@ -919,7 +919,7 @@ proc handleInstall(args: seq[Argument], config: Config, upgradeCount: int, nodep
clearPaths(paths)
let newKeepNames = keepNames.map(n => installedAs.opt(n).get(n))
- let (_, finalUnrequired, finalUnrequiredWithoutOptional) =
+ let (_, finalUnrequired, finalUnrequiredWithoutOptional, _) =
withAlpmConfig(config, false, handle, dbs, errors):
queryUnrequired(handle, true, true, newKeepNames)
@@ -1265,8 +1265,8 @@ proc resolveBuildTargets(config: Config, targets: seq[PackageTarget],
printMode, needed, upgradeCount)
for e in aperrors: printError(config.color, e)
- let upToDateNeededTable = upToDateNeeded.map(i => (i.name,
- (i.name, none(string), some((ConstraintOperation.eq, i.version))))).toTable
+ let upToDateNeededTable: Table[string, PackageReference] = upToDateNeeded.map(i => (i.name,
+ (i.name, none(string), some((ConstraintOperation.eq, i.version, false))))).toTable
let notFoundTargets = filterNotFoundSyncTargets(syncTargets,
aurPkgInfos, upToDateNeededTable)
diff --git a/src/package.nim b/src/package.nim
index bc55c3a..3e2c6f7 100644
--- a/src/package.nim
+++ b/src/package.nim
@@ -12,7 +12,8 @@ type
VersionConstraint* = tuple[
operation: ConstraintOperation,
- version: string
+ version: string,
+ impliedVersion: bool
]
PackageReference* = tuple[
@@ -195,13 +196,13 @@ proc toPackageReference*(dependency: ptr AlpmDependency): PackageReference =
else: none(ConstraintOperation)
let description = if dependency.desc != nil: some($dependency.desc) else: none(string)
- ($dependency.name, description, op.map(o => (o, $dependency.version)))
+ ($dependency.name, description, op.map(o => (o, $dependency.version, false)))
template toPackageReference*(pkg: ptr AlpmPackage): PackageReference =
- ($pkg.name, none(string), some((ConstraintOperation.eq, $pkg.version)))
+ ($pkg.name, none(string), some((ConstraintOperation.eq, $pkg.version, false)))
template toPackageReference*(pkg: RpcPackageInfo): PackageReference =
- (pkg.name, none(string), some((ConstraintOperation.eq, pkg.version)))
+ (pkg.name, none(string), some((ConstraintOperation.eq, pkg.version, false)))
proc parsePackageReference*(name: string, withDescription: bool): PackageReference =
var matches: array[3, string]
@@ -217,7 +218,7 @@ proc parsePackageReference*(name: string, withDescription: bool): PackageReferen
let index = constraints.map(s => $s).find(matches[1])
if index >= 0:
- (matches[0], description, some((constraints[index], matches[2])))
+ (matches[0], description, some((constraints[index], matches[2], false)))
else:
(matches[0], description, none(VersionConstraint))
else: