MCPcopy Index your code
hub / github.com/aptly-dev/aptly / ByKey

Method ByKey

deb/package_collection.go:53–109  ·  view source on GitHub ↗

ByKey find package in DB by its key

(key []byte)

Source from the content-addressed store, hash-verified

51
52// ByKey find package in DB by its key
53func (collection *PackageCollection) ByKey(key []byte) (*Package, error) {
54 encoded, err := collection.db.Get(key)
55 if err != nil {
56 return nil, err
57 }
58
59 p := &Package{}
60
61 if len(encoded) > 2 && (encoded[0] != 0xc1 || encoded[1] != 0x1) {
62 oldp := &oldPackage{}
63
64 decoder := codec.NewDecoderBytes(encoded, collection.codecHandle)
65 err = decoder.Decode(oldp)
66 if err != nil {
67 return nil, err
68 }
69
70 p.Name = oldp.Name
71 p.Version = oldp.Version
72 p.Architecture = oldp.Architecture
73 p.IsSource = oldp.IsSource
74 p.SourceArchitecture = oldp.SourceArchitecture
75 p.Source = oldp.Source
76 p.Provides = oldp.Provides
77
78 p.deps = &PackageDependencies{
79 Depends: oldp.Depends,
80 BuildDepends: oldp.BuildDepends,
81 BuildDependsInDep: oldp.BuildDependsInDep,
82 PreDepends: oldp.PreDepends,
83 Suggests: oldp.Suggests,
84 Recommends: oldp.Recommends,
85 }
86
87 p.extra = &oldp.Extra
88 for i := range oldp.Files {
89 oldp.Files[i].Filename = filepath.Base(oldp.Files[i].Filename)
90 }
91 p.UpdateFiles(PackageFiles(oldp.Files))
92
93 // Save in new format
94 err = collection.Update(p)
95 if err != nil {
96 return nil, err
97 }
98 } else {
99 decoder := codec.NewDecoderBytes(encoded[2:], collection.codecHandle)
100 err = decoder.Decode(p)
101 if err != nil {
102 return nil, err
103 }
104 }
105
106 p.collection = collection
107
108 return p, nil
109}
110

Callers 15

ScanMethod · 0.95
SearchByKeyMethod · 0.95
DiffMethod · 0.80
TestDownloadMethod · 0.80
TestDownloadFlatMethod · 0.80
BuildDownloadQueueMethod · 0.80
isDanglingFunction · 0.80
TestUpdateMethod · 0.80
TestByKeyMethod · 0.80

Calls 5

UpdateFilesMethod · 0.95
UpdateMethod · 0.95
PackageFilesTypeAlias · 0.85
GetMethod · 0.65
DecodeMethod · 0.45

Tested by 9

TestDownloadMethod · 0.64
TestDownloadFlatMethod · 0.64
TestUpdateMethod · 0.64
TestByKeyMethod · 0.64
TestByKeyOld0_3Method · 0.64
TestDeleteByKeyMethod · 0.64