| 1 | // the existing V API retains the package methods removed by pacman bdedf621. |
| 2 | // behavior follows package.c, util.c and be_sync.c immediately before that change. |
| 3 | module engine |
| 4 | |
| 5 | pub fn (mut handle Handle) check_package_md5sum(pkg &Package) int { |
| 6 | handle.check() or { return -1 } |
| 7 | if pkg == unsafe { nil } || pkg.origin != .sync_db || voidptr(pkg.owner) != voidptr(handle) { |
| 8 | handle.fail(.wrong_args, 'MD5 package checks require a sync package from this handle') |
| 9 | return -1 |
| 10 | } |
| 11 | if !pkg.has_filename && pkg.filename == '' { |
| 12 | handle.fail(.wrong_args, 'package has no filename') |
| 13 | return -1 |
| 14 | } |
| 15 | cached := handle.find_cached_file(pkg.filename) or { return -1 } |
| 16 | if !cached.found { return -1 } |
| 17 | computed := compute_md5sum(cached.path) or { return -1 } |
| 18 | if !pkg.has_md5sum { return -1 } |
| 19 | if pkg.md5sum != computed { |
| 20 | handle.fail(.pkg_invalid, pkg.filename) |
| 21 | return -1 |
| 22 | } |
| 23 | return 0 |
| 24 | } |
| 25 | |