Skip to content

Commit

Permalink
kpkg: support for replaces on getPackage, make isReplaced return a tu…
Browse files Browse the repository at this point in the history
…ple instead of a bool
  • Loading branch information
kreatoo committed Mar 20, 2024
1 parent 8e0ac60 commit e1cd8e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion kpkg/modules/commonTasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,6 @@ proc printReplacesPrompt*(pkgs: seq[string], root: string, isDeps = false, isIns
for p in parseRunfile(pkgRepo&"/"&pkg).replaces:
if isDeps and packageExists(p, root):
continue
if packageExists(p, root) and not isReplaced(p, root):
if packageExists(p, root) and not isReplaced(p, root).replaced:
info "'"&i&"' replaces '"&p&"'"

35 changes: 21 additions & 14 deletions kpkg/modules/sqlite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,34 @@ proc pkgSumstoSQL*(file: string, package: Package, root: string) =
else:
newFile(splittedLine[0], splittedLine[1], package, root)

proc isReplaced*(name: string, root = "/"): tuple[replaced: bool, package: Package] =
# Checks if a package is "replaced" or not.
rootCheck(root)

# feels wrong for some reason, hmu if theres a better way -kreatoo
var packages = @[newPackageInternal()]
kpkgDb.selectAll(packages)

for package in packages:
if name in package.replaces.split("!!k!!"):
return (true, package)

return (false, newPackageInternal())

proc getPackage*(name: string, root: string): Package =
# Gets Package from package name.
rootCheck(root)

debug "getPackage ran, name: '"&name&"', root: '"&root&"'"


var package = newPackageInternal()
kpkgDb.select(package, "name = ?", name)

package = isReplaced(name, root).package

if isEmptyOrWhitespace(package.name):
kpkgDb.select(package, "name = ?", name)

return package


Expand Down Expand Up @@ -131,19 +151,6 @@ proc getListPackages*(root = "/"): seq[string] =

return packageList

proc isReplaced*(name: string, root = "/"): bool =
# Checks if a package is "replaced" or not.
rootCheck(root)

# feels wrong for some reason, hmu if theres a better way -kreatoo
var packages = @[newPackageInternal()]
kpkgDb.selectAll(packages)

for package in packages:
if name in package.replaces.split("!!k!!"):
return true

return false

proc newPackageFromRoot*(root, package, destdir: string) =
# Gets package from root, and adds it to destdir.
Expand Down

0 comments on commit e1cd8e3

Please sign in to comment.