Repository now support Revision and LastUpdate

This commit is contained in:
Daniele Rondina
2020-01-03 20:09:29 +01:00
parent 6af62b5851
commit d3bd78d618
2 changed files with 20 additions and 1 deletions

View File

@@ -56,7 +56,14 @@ type LuetRepository struct {
Priority int `json:"priority,omitempty" yaml:"priority,omitempty" mapstructure:"priority"`
Enable bool `json:"enable" yaml:"enable" mapstructure:"enable"`
Authentication map[string]string `json:"auth,omitempty" yaml:"auth,omitempty" mapstructure:"auth,omitempty"`
TreePath string `json:"tree_path,omitempty" yaml::"tree_path,omitempty" mapstructure:"tree_path"`
TreePath string `json:"tree_path,omitempty" yaml:"tree_path,omitempty" mapstructure:"tree_path"`
// Serialized options not used in repository configuration
// Incremented value that identify revision of the repository in a user-friendly way.
Revision int `json:"revision,omitempty" yaml:"-,omitempty" mapstructure:"-,omitempty"`
// Epoch time in seconds
LastUpdate string `json:"last_update,omitempty" yaml:"-,omitempty" mapstructure:"-,omitempty"`
}
func NewLuetRepository(name, t, descr string, urls []string, priority int, enable bool) *LuetRepository {

View File

@@ -21,7 +21,9 @@ import (
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"time"
"github.com/mudler/luet/pkg/installer/client"
@@ -49,6 +51,8 @@ type LuetSystemRepositorySerialized struct {
Priority int `json:"priority"`
Index []*compiler.PackageArtifact `json:"index"`
Type string `json:"type"`
Revision int `json:"revision,omitempty"`
LastUpdate string `json:"last_update,omitempty"`
}
func GenerateRepository(name, descr, t string, urls []string, priority int, src, treeDir string, db pkg.PackageDatabase) (Repository, error) {
@@ -98,6 +102,12 @@ func NewLuetSystemRepositoryFromYaml(data []byte, db pkg.PackageDatabase) (Repos
true,
),
}
if p.Revision > 0 {
r.Revision = p.Revision
}
if p.LastUpdate != "" {
r.LastUpdate = p.LastUpdate
}
i := compiler.ArtifactIndex{}
for _, ii := range p.Index {
i = append(i, ii)
@@ -185,6 +195,8 @@ func (r *LuetSystemRepository) Write(dst string) error {
return err
}
r.Index = r.Index.CleanPath()
r.LastUpdate = strconv.FormatInt(time.Now().Unix(), 10)
r.Revision++
data, err := yaml.Marshal(r)
if err != nil {