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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
package zoopb
import (
"go.wit.com/lib/fhelp"
"go.wit.com/log"
)
// this is the default table layout for repos in forge
func (pb *Packages) PrintTable() {
tablePB := pb.makeDefaultTable()
tablePB.PrintTable()
}
func (pb *Packages) makeDefaultTable() *PackagesTable {
t := pb.NewTable("apt packages")
t.NewUuid()
var col *PackageFunc
col = t.AddStringFunc(" I", func(p *Package) string {
if p.Installed {
return " X"
}
return ""
})
col.Width = 3
col = t.AddName()
col.Width = 30
col = t.AddVersion()
col.Width = 20
col = t.AddPkgName()
col.Width = -1
col.Header.Name = "apt package path"
return t
}
func (m *Machine) PrintTable(pb *Packages) {
tablePB := m.makeSmartTable(pb)
tablePB.PrintTable()
}
func (m *Machine) makeSmartTable(pb *Packages) *PackagesTable {
t := pb.NewTable("apt packages")
t.NewUuid()
var col *PackageFunc
col = t.AddStringFunc(" I", func(p *Package) string {
if m.IsInstalled(p.Name) {
return " X"
}
return ""
})
col.Width = 3
col = t.AddStringFunc("U", func(p *Package) string {
if m.WillUpgrade(p) {
return "X"
}
return ""
})
col.Width = 1
col = t.AddStringFunc("BAD", func(p *Package) string {
if m.MirrorsOutOfDate(p) {
return "BAD"
}
return ""
})
col.Width = 3
col = t.AddName()
col.Width = 30
col = t.AddVersion()
col.Width = 20
col = t.AddPkgName()
col.Width = -1
col.Header.Name = "apt package path"
return t
}
// true if the package 'p' is newer than the installed package
func (m *Machine) WillUpgrade(p *Package) bool {
check := m.FindInstalledByName(p.Name)
if check == nil {
// not installed. can not upgrade
return false
}
v1, _ := fhelp.NewDebVersion(check.Version)
v2, _ := fhelp.NewDebVersion(p.Version)
if v1.Equal(v2) {
// log.Info("do nothing", v1, v2)
return false
}
if v1.LessThan(v2) {
log.Info("upgrading from", v1, "to", v2)
return true
}
log.Info("WEIRD: keeping on machine version:", v1, "newer than mirrors.wit.com:", v2)
return false
}
// this means somehow this machine has a newer version than the mirrors have
// true if the package 'p' is newer than the installed package
func (m *Machine) MirrorsOutOfDate(p *Package) bool {
check := m.FindInstalledByName(p.Name)
if check == nil {
// not installed
return false
}
v1, _ := fhelp.NewDebVersion(check.Version)
v2, _ := fhelp.NewDebVersion(p.Version)
if v1.Equal(v2) {
// log.Info("do nothing", v1, v2)
return false
}
if v2.LessThan(v1) {
log.Info("wow. you have a newer version on this box than the mirrors", v1, "to", v2)
return true
}
return false
}
|