| 1 | module main |
| 2 | |
| 3 | import alpm |
| 4 | |
| 5 | struct ConfigDeptest { |
| 6 | pub mut: |
| 7 | show_help bool @[long: help; short: h] |
| 8 | query []string @[tail] |
| 9 | } |
| 10 | |
| 11 | // unsatisfied_deps are the dependencies no installed package satisfies, in |
| 12 | // the order and the spelling they were given |
| 13 | fn unsatisfied_deps(pkgcache &alpm.List, deps []string) []string { |
| 14 | mut out := []string{} |
| 15 | for dep in deps { |
| 16 | if _ := pkgcache.find_satisfier(dep) { |
| 17 | continue |
| 18 | } |
| 19 | out << dep |
| 20 | } |
| 21 | return out |
| 22 | } |
| 23 | |
| 24 | // deptest is pacman's -T: it prints every dependency no installed package |
| 25 | // satisfies and returns them; main exits 127 when there is one, the code |
| 26 | // makepkg tells apart from a failure. it changes nothing, so it needs no root |
| 27 | fn deptest(config ConfigDeptest) ![]string { |
| 28 | need_query(config.query, 'dependency')! |
| 29 | handle := alpm.initialize(root_path, db_path) or { return err } |
| 30 | defer { handle.release() or { went_on('release the alpm handle', err) } } |
| 31 | pkgcache := local_pkgcache(handle)! |
| 32 | missing := unsatisfied_deps(pkgcache, config.query) |
| 33 | if ipc_on() { |
| 34 | emit(UnsatisfiedEvent{ |
| 35 | deps: missing |
| 36 | }) |
| 37 | } else { |
| 38 | for dep in missing { |
| 39 | println(dep) |
| 40 | } |
| 41 | } |
| 42 | // the defer above releases the handle; a second release here would free |
| 43 | // it twice |
| 44 | return missing |
| 45 | } |
| 46 | |