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

Method ForEachSorted

deb/snapshot.go:368–394  ·  view source on GitHub ↗

ForEachSorted runs method for each snapshot following some sort order

(sortMethod string, handler func(*Snapshot) error)

Source from the content-addressed store, hash-verified

366
367// ForEachSorted runs method for each snapshot following some sort order
368func (collection *SnapshotCollection) ForEachSorted(sortMethod string, handler func(*Snapshot) error) error {
369 blobs := collection.db.FetchByPrefix([]byte("S"))
370 list := make([]*Snapshot, 0, len(blobs))
371
372 for _, blob := range blobs {
373 s := &Snapshot{}
374 if err := s.Decode(blob); err != nil {
375 log.Printf("Error decoding snapshot: %s\n", err)
376 } else {
377 list = append(list, s)
378 }
379 }
380
381 sorter, err := newSnapshotSorter(sortMethod, list)
382 if err != nil {
383 return err
384 }
385
386 for _, s := range sorter.list {
387 err = handler(s)
388 if err != nil {
389 return err
390 }
391 }
392
393 return nil
394}
395
396// Len returns number of snapshots in collection
397// ForEach runs method for each snapshot

Callers 4

TestForEachSortedMethod · 0.80
aptlySnapshotListTxtFunction · 0.80
aptlySnapshotListJSONFunction · 0.80
apiSnapshotsListFunction · 0.80

Calls 4

newSnapshotSorterFunction · 0.85
FetchByPrefixMethod · 0.65
PrintfMethod · 0.65
DecodeMethod · 0.45

Tested by 1

TestForEachSortedMethod · 0.64