loadContents loads or calculates and saves package contents
(p *Package, packagePool aptly.PackagePool, progress aptly.Progress)
| 164 | |
| 165 | // loadContents loads or calculates and saves package contents |
| 166 | func (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 |
| 205 | func (collection *PackageCollection) Update(p *Package) error { |