Skip to content

Commit

Permalink
kpkg: commands/checkcmd: fix checkInternal
Browse files Browse the repository at this point in the history
  • Loading branch information
kreatoo committed Dec 23, 2024
1 parent 29aabb8 commit 1b071eb
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions kpkg/commands/checkcmd.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,32 @@ import ../modules/sqlite
import ../modules/logger
import ../modules/checksums

proc checkInternal(package: string, root: string, lines: seq[string], checkEtc: bool) =
proc checkInternal(package: Package, root: string, lines = getFilesPackage(package, root), checkEtc: bool) =
for line in lines:

if dirExists(line):
let actPath = line.path.replace("\"", "")
let fullPath = root&"/"&actPath

if dirExists(fullPath):
continue

if line.parentDir().lastPathPart == "etc" and (not checkEtc):
if actPath.parentDir().lastPathPart == "etc" and (not checkEtc):
continue

let splitted = line.split("=")

if splitted.len < 2:
if line.blake2Checksum == "":
#debug "'"&line&"' doesn't have checksum, skipping"
continue

let filePath = root&"/"&splitted[0].multiReplace(("\"", ""))
if getSum(filePath, "b2") != splitted[1].multiReplace(("\"", "")):
let errorOutput = "'"&filePath.relativePath(root)&"' has an invalid checksum, please reinstall '"&package&"'"
when defined(release):
let sum = line.blake2Checksum
let actualSum = getSum(fullPath, "b2")

debug "checking '"&fullPath.relativePath(root)&"' with checksum '"&sum&"' and actual checksum '"&actualSum&"'"

if actualSum != sum:
let errorOutput = "'"&fullPath.relativePath(root)&"' has an invalid checksum, please reinstall '"&package.name&"'"
debug errorOutput
if not isDebugMode():
err errorOutput
else:
debug errorOutput

proc check*(package = "", root = "/", silent = false, checkEtc = false) =
## Check packages in filesystem for errors.
Expand All @@ -35,12 +39,14 @@ proc check*(package = "", root = "/", silent = false, checkEtc = false) =

if isEmptyOrWhitespace(package):
for pkg in getListPackages(root):
checkInternal(pkg, root, getListFiles(pkg, root), checkEtc)
let p = getPackage(package, root)
checkInternal(p, root, getFilesPackage(p, root), checkEtc)
else:
if not packageExists(package, root):
err("package '"&package&"' doesn't exist", false)
else:
checkInternal(package, root, getListFiles(package, root), checkEtc)
let p = getPackage(package, root)
checkInternal(p, root, getFilesPackage(p, root), checkEtc)

if not silent:
success("done")
Expand Down

0 comments on commit 1b071eb

Please sign in to comment.