-
Notifications
You must be signed in to change notification settings - Fork 4
/
pkg.go
60 lines (48 loc) · 1.01 KB
/
pkg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"github.com/lhcb-org/lbpkr/yum"
)
type Package struct {
*yum.Package
Mode Mode
}
type PackagesByDepGraph struct {
ctx *Context
pkgs []Package
}
func (p PackagesByDepGraph) Len() int {
return len(p.pkgs)
}
func (p PackagesByDepGraph) Swap(i, j int) {
p.pkgs[i], p.pkgs[j] = p.pkgs[j], p.pkgs[i]
}
func (p PackagesByDepGraph) Less(i, j int) bool {
pi := p.pkgs[i]
pj := p.pkgs[j]
// check whether package 'i' (or one of its deps) needs 'j'
di, err := p.ctx.yum.RequiredPackages(pi.Package, -1)
if err != nil {
panic(err)
}
for _, ii := range di {
if ii.RPMName() == pj.RPMName() {
// i (or one of its deps) needs package 'j'
// so correct order is: j <= i
return false
}
}
if true {
return true
}
pir, err := p.ctx.getNotInstalledPackageDeps(pi)
if err != nil {
panic(err)
}
pjr, err := p.ctx.getNotInstalledPackageDeps(pj)
if err != nil {
panic(err)
}
// i deps do not overlap with j.
// order by un-installed dependencies
return len(pir) < len(pjr)
}