vpac / src / deptest.v
45 lines · 41 sloc · 1.19 KB · 3609dfbd82867dc1034a443f8f9ced529ddbbedd
Raw
1module main
2
3import alpm
4
5struct ConfigDeptest {
6pub 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
13fn 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
27fn 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