diff --git a/cmd/install.go b/cmd/install.go index 2fc8bac6..29e747de 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -74,7 +74,6 @@ var installCmd = &cobra.Command{ inst := installer.NewLuetInstaller(LuetCfg.GetGeneral().Concurrency) inst.Repositories(repos) - inst.SyncRepositories() if LuetCfg.GetSystem().DatabaseEngine == "boltdb" { systemDB = pkg.NewBoltDatabase( diff --git a/pkg/config/config.go b/pkg/config/config.go index ded53472..dd5787d1 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -46,15 +46,15 @@ type LuetSystemConfig struct { } type LuetRepository struct { - Name string `yaml:"name" mapstructure:"name"` - Description string `yaml:"description,omitempty" mapstructure:"description"` - Urls []string `yaml:"urls" mapstructure:"urls"` - Type string `yaml:"type" mapstructure:"type"` - Mode string `yaml:"mode,omitempty" mapstructure:"mode"` - Priority int `yaml:"priority,omitempty" mapstructure:"priority"` - Enable bool `yaml:"enable" mapstructure:"enable"` - Authentication map[string]string `yaml:"auth,omitempty" mapstructure:"auth"` - TreePath string `yaml::"tree_path,omitempty" mapstructure:"tree_path"` + Name string `json:"name" yaml:"name" mapstructure:"name"` + Description string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description"` + Urls []string `json:"urls" yaml:"urls" mapstructure:"urls"` + Type string `json:"type" yaml:"type" mapstructure:"type"` + Mode string `json:"mode,omitempty" yaml:"mode,omitempty" mapstructure:"mode,omitempty"` + 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"` } func NewLuetRepository(name, t, descr string, urls []string, priority int, enable bool) *LuetRepository { diff --git a/pkg/installer/installer.go b/pkg/installer/installer.go index 1ddc498a..90d80228 100644 --- a/pkg/installer/installer.go +++ b/pkg/installer/installer.go @@ -123,14 +123,14 @@ func (l *LuetInstaller) Upgrade(s *System) error { return l.Install(toInstall, s) } -func (l *LuetInstaller) SyncRepositories() error { +func (l *LuetInstaller) SyncRepositories(inMemory bool) (Repositories, error) { Spinner(32) defer SpinnerStop() syncedRepos := Repositories{} for _, r := range l.PackageRepositories { repo, err := r.Sync() if err != nil { - return errors.Wrap(err, "Failed syncing repository: "+r.GetName()) + return nil, errors.Wrap(err, "Failed syncing repository: "+r.GetName()) } syncedRepos = append(syncedRepos, repo) } @@ -138,9 +138,11 @@ func (l *LuetInstaller) SyncRepositories() error { // compute what to install and from where sort.Sort(syncedRepos) - l.PackageRepositories = syncedRepos + if !inMemory { + l.PackageRepositories = syncedRepos + } - return nil + return syncedRepos, nil } func (l *LuetInstaller) Install(cp []pkg.Package, s *System) error { @@ -166,23 +168,28 @@ func (l *LuetInstaller) Install(cp []pkg.Package, s *System) error { } // First get metas from all repos (and decodes trees) + syncedRepos, err := l.SyncRepositories(true) + if err != nil { + return err + } // First match packages against repositories by priority // matches := syncedRepos.PackageMatches(p) // compute a "big" world allRepos := pkg.NewInMemoryDatabase(false) - l.PackageRepositories.SyncDatabase(allRepos) + syncedRepos.SyncDatabase(allRepos) solv := solver.NewSolver(s.Database, allRepos, pkg.NewInMemoryDatabase(false)) solution, err := solv.Install(p) if err != nil { return errors.Wrap(err, "Failed solving solution for package") } + // Gathers things to install toInstall := map[string]ArtifactMatch{} for _, assertion := range solution { if assertion.Value { - matches := l.PackageRepositories.PackageMatches([]pkg.Package{assertion.Package}) + matches := syncedRepos.PackageMatches([]pkg.Package{assertion.Package}) if len(matches) != 1 { return errors.New("Failed matching solutions against repository - where are definitions coming from?!") } diff --git a/pkg/installer/interface.go b/pkg/installer/interface.go index 9899bb86..424ae365 100644 --- a/pkg/installer/interface.go +++ b/pkg/installer/interface.go @@ -27,7 +27,7 @@ type Installer interface { Uninstall(pkg.Package, *System) error Upgrade(s *System) error Repositories([]Repository) - SyncRepositories() error + SyncRepositories(bool) (Repositories, error) } type Client interface {