MCPcopy Create free account
hub / github.com/aptly-dev/aptly / loadContents

Method loadContents

deb/package_collection.go:166–202  ·  view source on GitHub ↗

loadContents loads or calculates and saves package contents

(p *Package, packagePool aptly.PackagePool, progress aptly.Progress)

Source from the content-addressed store, hash-verified

164
165// loadContents loads or calculates and saves package contents
166func (collection *PackageCollection) loadContents(p *Package, packagePool aptly.PackagePool, progress aptly.Progress) []string {
167 encoded, err := collection.db.Get(p.Key("xC"))
168 if err == nil {
169 contents := []string{}
170
171 decoder := codec.NewDecoderBytes(encoded, collection.codecHandle)
172 err = decoder.Decode(&contents)
173 if err != nil {
174 panic("unable to decode contents")
175 }
176
177 return contents
178 }
179
180 if err != database.ErrNotFound {
181 panic("unable to load contents")
182 }
183
184 contents, err := p.CalculateContents(packagePool, progress)
185 if err != nil {
186 // failed to acquire contents, don't persist it
187 return contents
188 }
189
190 var buf bytes.Buffer
191 err = codec.NewEncoder(&buf, collection.codecHandle).Encode(contents)
192 if err != nil {
193 panic("unable to encode contents")
194 }
195
196 err = collection.db.Put(p.Key("xC"), buf.Bytes())
197 if err != nil {
198 panic("unable to save contents")
199 }
200
201 return contents
202}
203
204// Update adds or updates information about package in DB
205func (collection *PackageCollection) Update(p *Package) error {

Callers 1

ContentsMethod · 0.80

Calls 6

CalculateContentsMethod · 0.80
GetMethod · 0.65
PutMethod · 0.65
KeyMethod · 0.45
DecodeMethod · 0.45
EncodeMethod · 0.45

Tested by

no test coverage detected