File: utils.go

package info (click to toggle)
incus 6.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 23,864 kB
  • sloc: sh: 16,015; ansic: 3,121; python: 456; makefile: 321; ruby: 51; sql: 50; lisp: 6
file content (41 lines) | stat: -rw-r--r-- 799 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

import (
	"encoding/json"
	"os"

	"github.com/lxc/incus/v6/shared/simplestreams"
)

func writeIndex(products *simplestreams.Products) error {
	// Update the product list.
	productNames := make([]string, 0, len(products.Products))
	for name := range products.Products {
		productNames = append(productNames, name)
	}

	// Write a new index file.
	stream := simplestreams.Stream{
		Format: "index:1.0",
		Index: map[string]simplestreams.StreamIndex{
			"images": {
				DataType: "image-downloads",
				Path:     "streams/v1/images.json",
				Format:   "products:1.0",
				Products: productNames,
			},
		},
	}

	body, err := json.Marshal(&stream)
	if err != nil {
		return err
	}

	err = os.WriteFile("streams/v1/index.json", body, 0o644)
	if err != nil {
		return err
	}

	return nil
}