MCPcopy
hub / github.com/aptly-dev/aptly / Add

Method Add

deb/list.go:137–161  ·  view source on GitHub ↗

Add appends package to package list, additionally checking for uniqueness

(p *Package)

Source from the content-addressed store, hash-verified

135
136// Add appends package to package list, additionally checking for uniqueness
137func (l *PackageList) Add(p *Package) error {
138 key := l.keyFunc(p)
139 existing, ok := l.packages[key]
140 if ok {
141 if !existing.Equals(p) {
142 return &PackageConflictError{fmt.Errorf("package already exists and is different: %s", p)}
143 }
144 return nil
145 }
146 l.packages[key] = p
147
148 if l.indexed {
149 for _, provides := range p.ProvidedPackages() {
150 l.providesIndex[provides] = append(l.providesIndex[provides], p)
151 }
152
153 i := sort.Search(len(l.packagesIndex), func(j int) bool { return l.lessPackages(p, l.packagesIndex[j]) })
154
155 // insert p into l.packagesIndex in position i
156 l.packagesIndex = append(l.packagesIndex, nil)
157 copy(l.packagesIndex[i+1:], l.packagesIndex[i:])
158 l.packagesIndex[i] = p
159 }
160 return nil
161}
162
163// ForEach calls handler for each package in list
164func (l *PackageList) ForEach(handler func(*Package) error) error {

Callers 15

TestAppendMethod · 0.95
TestFilterLatestMethod · 0.95
TestDiffMethod · 0.95
TestDiffCompactsAtEndMethod · 0.95
TestMergeMethod · 0.95
TestFilterLatestRefsMethod · 0.95
FilterMethod · 0.95
apiSnapshotsCreateFunction · 0.95
makePackageRefListFunction · 0.95
validEntityFunction · 0.45
WriteMethod · 0.45
AddBarMethod · 0.45

Calls 4

lessPackagesMethod · 0.95
EqualsMethod · 0.80
ProvidedPackagesMethod · 0.80
SearchMethod · 0.65

Tested by 15

TestAppendMethod · 0.76
TestFilterLatestMethod · 0.76
TestDiffMethod · 0.76
TestDiffCompactsAtEndMethod · 0.76
TestMergeMethod · 0.76
TestFilterLatestRefsMethod · 0.76
makePackageRefListFunction · 0.76
SetUpPackagesMethod · 0.36
TestAddByNameMethod · 0.36