104
105
// NewVersionedToolsConstraint returns a ToolsConstraint for a tools with a specific version.
105
func NewVersionedToolsConstraint(vers string, params simplestreams.LookupParams) *ToolsConstraint {
106
versNum := version.MustParse(vers)
107
return &ToolsConstraint{LookupParams: params, Version: versNum}
106
func NewVersionedToolsConstraint(vers version.Number, params simplestreams.LookupParams) *ToolsConstraint {
107
return &ToolsConstraint{LookupParams: params, Version: vers}
110
110
// NewGeneralToolsConstraint returns a ToolsConstraint for tools with matching major/minor version numbers.
168
168
// The base URL locations are as specified - the first location which has a file is the one used.
169
169
// Signed data is preferred, but if there is no signed data available and onlySigned is false,
170
170
// then unsigned data is used.
171
func Fetch(sources []simplestreams.DataSource, indexPath string, cons *ToolsConstraint, onlySigned bool) ([]*ToolsMetadata, error) {
172
sources []simplestreams.DataSource, indexPath string, cons *ToolsConstraint,
173
onlySigned bool) ([]*ToolsMetadata, *simplestreams.ResolveInfo, error) {
172
175
params := simplestreams.ValueParams{
173
176
DataType: ContentDownload,
174
177
FilterFunc: appendMatchingTools,
176
179
ValueTemplate: ToolsMetadata{},
177
180
PublicKey: simplestreamsToolsPublicKey,
179
items, err := simplestreams.GetMetadata(sources, indexPath, cons, onlySigned, params)
182
items, resolveInfo, err := simplestreams.GetMetadata(sources, indexPath, cons, onlySigned, params)
183
186
metadata := make([]*ToolsMetadata, len(items))
184
187
for i, md := range items {
185
188
metadata[i] = md.(*ToolsMetadata)
190
// Sorting the metadata is not strictly necessary, but it ensures consistent ordering for
191
// all compilers, and it just makes it easier to look at the data.
193
return metadata, resolveInfo, nil
196
// Sort sorts a slice of ToolsMetadata in ascending order of their version
197
// in order to ensure the results of Fetch are ordered deterministically.
198
func Sort(metadata []*ToolsMetadata) {
199
sort.Sort(byVersion(metadata))
202
type byVersion []*ToolsMetadata
204
func (b byVersion) Len() int { return len(b) }
205
func (b byVersion) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
206
func (b byVersion) Less(i, j int) bool { return b[i].binary().String() < b[j].binary().String() }
190
208
// appendMatchingTools updates matchingTools with tools metadata records from tools which belong to the
191
209
// specified series. If a tools record already exists in matchingTools, it is not overwritten.
306
324
for _, metadata := range merged {
307
325
list = append(list, metadata)
312
331
// ReadMetadata returns the tools metadata from the given storage.
313
332
func ReadMetadata(store storage.StorageReader) ([]*ToolsMetadata, error) {
314
dataSource := storage.NewStorageSimpleStreamsDataSource(store, storage.BaseToolsPath)
333
dataSource := storage.NewStorageSimpleStreamsDataSource("existing metadata", store, storage.BaseToolsPath)
315
334
toolsConstraint, err := makeToolsConstraint(simplestreams.CloudSpec{}, -1, -1, coretools.Filter{})
319
metadata, err := Fetch([]simplestreams.DataSource{dataSource}, simplestreams.DefaultIndexPath, toolsConstraint, false)
338
metadata, _, err := Fetch(
339
[]simplestreams.DataSource{dataSource}, simplestreams.DefaultIndexPath, toolsConstraint, false)
320
340
if err != nil && !errors.IsNotFoundError(err) {