2019-11-22 20:01:38 +00:00
|
|
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package installer
|
|
|
|
|
|
|
|
import (
|
2020-01-03 23:31:11 +00:00
|
|
|
"fmt"
|
2019-11-22 20:01:38 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2020-01-28 16:46:32 +00:00
|
|
|
"path"
|
2019-11-22 20:01:38 +00:00
|
|
|
"path/filepath"
|
|
|
|
"sort"
|
2020-01-03 19:09:29 +00:00
|
|
|
"strconv"
|
2019-11-22 20:01:38 +00:00
|
|
|
"strings"
|
2020-01-03 19:09:29 +00:00
|
|
|
"time"
|
2019-11-22 20:01:38 +00:00
|
|
|
|
|
|
|
"github.com/mudler/luet/pkg/compiler"
|
2019-12-31 00:21:06 +00:00
|
|
|
"github.com/mudler/luet/pkg/config"
|
2019-11-22 20:01:38 +00:00
|
|
|
"github.com/mudler/luet/pkg/helpers"
|
2020-01-12 22:31:43 +00:00
|
|
|
"github.com/mudler/luet/pkg/installer/client"
|
2020-01-02 17:31:25 +00:00
|
|
|
. "github.com/mudler/luet/pkg/logger"
|
2019-11-22 20:01:38 +00:00
|
|
|
pkg "github.com/mudler/luet/pkg/package"
|
|
|
|
tree "github.com/mudler/luet/pkg/tree"
|
2020-01-12 22:31:43 +00:00
|
|
|
|
|
|
|
"github.com/ghodss/yaml"
|
|
|
|
. "github.com/logrusorgru/aurora"
|
2019-11-22 20:01:38 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2020-01-03 23:31:11 +00:00
|
|
|
const (
|
2020-03-23 22:56:29 +00:00
|
|
|
REPOSITORY_METAFILE = "repository.meta.yaml"
|
2020-01-03 23:31:11 +00:00
|
|
|
REPOSITORY_SPECFILE = "repository.yaml"
|
2020-01-04 23:40:28 +00:00
|
|
|
TREE_TARBALL = "tree.tar"
|
2020-03-23 22:56:29 +00:00
|
|
|
|
|
|
|
REPOFILE_TREE_KEY = "tree"
|
|
|
|
REPOFILE_META_KEY = "meta"
|
2020-01-03 23:31:11 +00:00
|
|
|
)
|
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
type LuetRepositoryFile struct {
|
2020-03-24 17:30:52 +00:00
|
|
|
FileName string `json:"filename"`
|
2020-03-23 22:56:29 +00:00
|
|
|
CompressionType compiler.CompressionImplementation `json:"compressiontype,omitempty"`
|
|
|
|
Checksums compiler.Checksums `json:"checksums,omitempty"`
|
|
|
|
}
|
|
|
|
|
2019-12-31 00:21:06 +00:00
|
|
|
type LuetSystemRepository struct {
|
|
|
|
*config.LuetRepository
|
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
Index compiler.ArtifactIndex `json:"index"`
|
|
|
|
Tree tree.Builder `json:"-"`
|
|
|
|
RepositoryFiles map[string]LuetRepositoryFile `json:"repo_files"`
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 00:21:06 +00:00
|
|
|
type LuetSystemRepositorySerialized struct {
|
2020-03-23 22:56:29 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
Urls []string `json:"urls"`
|
|
|
|
Priority int `json:"priority"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Revision int `json:"revision,omitempty"`
|
|
|
|
LastUpdate string `json:"last_update,omitempty"`
|
|
|
|
TreePath string `json:"treepath"`
|
|
|
|
MetaPath string `json:"metapath"`
|
|
|
|
RepositoryFiles map[string]LuetRepositoryFile `json:"repo_files"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type LuetSystemRepositoryMetadata struct {
|
|
|
|
Index []*compiler.PackageArtifact `json:"index,omitempty"`
|
2019-11-23 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 22:47:35 +00:00
|
|
|
type LuetSearchModeType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
SLabel LuetSearchModeType = "label"
|
|
|
|
SRegexPkg LuetSearchModeType = "regexPkg"
|
|
|
|
SRegexLabel LuetSearchModeType = "regexLabel"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LuetSearchOpts struct {
|
|
|
|
Pattern string
|
|
|
|
Mode LuetSearchModeType
|
|
|
|
}
|
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
func NewLuetSystemRepositoryMetadata(file string, removeFile bool) (*LuetSystemRepositoryMetadata, error) {
|
|
|
|
ans := &LuetSystemRepositoryMetadata{}
|
|
|
|
err := ans.ReadFile(file, removeFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return ans, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *LuetSystemRepositoryMetadata) WriteFile(path string) error {
|
|
|
|
data, err := yaml.Marshal(m)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ioutil.WriteFile(path, data, os.ModePerm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *LuetSystemRepositoryMetadata) ReadFile(file string, removeFile bool) error {
|
|
|
|
if file == "" {
|
|
|
|
return errors.New("Invalid path for repository metadata")
|
|
|
|
}
|
|
|
|
|
|
|
|
dat, err := ioutil.ReadFile(file)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if removeFile {
|
|
|
|
defer os.Remove(file)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = yaml.Unmarshal(dat, m)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *LuetSystemRepositoryMetadata) ToArtificatIndex() (ans compiler.ArtifactIndex) {
|
|
|
|
for _, a := range m.Index {
|
|
|
|
ans = append(ans, a)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultTreeRepositoryFile() LuetRepositoryFile {
|
|
|
|
return LuetRepositoryFile{
|
2020-03-24 17:30:52 +00:00
|
|
|
FileName: TREE_TARBALL,
|
2020-03-23 22:56:29 +00:00
|
|
|
CompressionType: compiler.GZip,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultMetaRepositoryFile() LuetRepositoryFile {
|
|
|
|
return LuetRepositoryFile{
|
2020-03-24 17:30:52 +00:00
|
|
|
FileName: REPOSITORY_METAFILE + ".tar",
|
2020-03-23 22:56:29 +00:00
|
|
|
CompressionType: compiler.None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:30:52 +00:00
|
|
|
func (f *LuetRepositoryFile) SetFileName(n string) {
|
|
|
|
f.FileName = n
|
2020-03-23 22:56:29 +00:00
|
|
|
}
|
2020-03-24 17:30:52 +00:00
|
|
|
func (f *LuetRepositoryFile) GetFileName() string {
|
|
|
|
return f.FileName
|
2020-03-23 22:56:29 +00:00
|
|
|
}
|
|
|
|
func (f *LuetRepositoryFile) SetCompressionType(c compiler.CompressionImplementation) {
|
|
|
|
f.CompressionType = c
|
|
|
|
}
|
|
|
|
func (f *LuetRepositoryFile) GetCompressionType() compiler.CompressionImplementation {
|
|
|
|
return f.CompressionType
|
|
|
|
}
|
|
|
|
func (f *LuetRepositoryFile) SetChecksums(c compiler.Checksums) {
|
|
|
|
f.Checksums = c
|
|
|
|
}
|
|
|
|
func (f *LuetRepositoryFile) GetChecksums() compiler.Checksums {
|
|
|
|
return f.Checksums
|
|
|
|
}
|
|
|
|
|
2019-12-31 00:21:06 +00:00
|
|
|
func GenerateRepository(name, descr, t string, urls []string, priority int, src, treeDir string, db pkg.PackageDatabase) (Repository, error) {
|
2019-11-22 20:01:38 +00:00
|
|
|
|
|
|
|
art, err := buildPackageIndex(src)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-11-22 22:24:22 +00:00
|
|
|
tr := tree.NewInstallerRecipe(db)
|
|
|
|
err = tr.Load(treeDir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-11-22 20:01:38 +00:00
|
|
|
|
2019-12-31 00:21:06 +00:00
|
|
|
return NewLuetSystemRepository(
|
2020-01-12 22:31:43 +00:00
|
|
|
config.NewLuetRepository(name, t, descr, urls, priority, true, false),
|
2019-12-31 00:21:06 +00:00
|
|
|
art, tr), nil
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 17:31:25 +00:00
|
|
|
func NewSystemRepository(repo config.LuetRepository) Repository {
|
2019-12-31 00:21:06 +00:00
|
|
|
return &LuetSystemRepository{
|
2020-03-23 22:56:29 +00:00
|
|
|
LuetRepository: &repo,
|
|
|
|
RepositoryFiles: map[string]LuetRepositoryFile{},
|
2019-12-31 00:21:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewLuetSystemRepository(repo *config.LuetRepository, art []compiler.Artifact, builder tree.Builder) Repository {
|
|
|
|
return &LuetSystemRepository{
|
2020-03-23 22:56:29 +00:00
|
|
|
LuetRepository: repo,
|
|
|
|
Index: art,
|
|
|
|
Tree: builder,
|
|
|
|
RepositoryFiles: map[string]LuetRepositoryFile{},
|
2019-12-31 00:21:06 +00:00
|
|
|
}
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 00:21:06 +00:00
|
|
|
func NewLuetSystemRepositoryFromYaml(data []byte, db pkg.PackageDatabase) (Repository, error) {
|
|
|
|
var p *LuetSystemRepositorySerialized
|
2019-11-22 20:01:38 +00:00
|
|
|
err := yaml.Unmarshal(data, &p)
|
|
|
|
if err != nil {
|
2019-11-23 14:42:05 +00:00
|
|
|
return nil, err
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
2020-03-23 22:56:29 +00:00
|
|
|
|
2019-12-31 00:21:06 +00:00
|
|
|
r := &LuetSystemRepository{
|
|
|
|
LuetRepository: config.NewLuetRepository(
|
|
|
|
p.Name,
|
|
|
|
p.Type,
|
|
|
|
p.Description,
|
|
|
|
p.Urls,
|
|
|
|
p.Priority,
|
|
|
|
true,
|
2020-01-12 22:31:43 +00:00
|
|
|
false,
|
2019-12-31 00:21:06 +00:00
|
|
|
),
|
2020-03-24 11:52:24 +00:00
|
|
|
RepositoryFiles: p.RepositoryFiles,
|
2019-12-31 00:21:06 +00:00
|
|
|
}
|
2020-01-03 19:09:29 +00:00
|
|
|
if p.Revision > 0 {
|
|
|
|
r.Revision = p.Revision
|
|
|
|
}
|
|
|
|
if p.LastUpdate != "" {
|
|
|
|
r.LastUpdate = p.LastUpdate
|
|
|
|
}
|
2019-11-23 14:42:05 +00:00
|
|
|
r.Tree = tree.NewInstallerRecipe(db)
|
|
|
|
|
|
|
|
return r, err
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func buildPackageIndex(path string) ([]compiler.Artifact, error) {
|
|
|
|
|
|
|
|
var art []compiler.Artifact
|
|
|
|
var ff = func(currentpath string, info os.FileInfo, err error) error {
|
|
|
|
|
|
|
|
if !strings.HasSuffix(info.Name(), ".metadata.yaml") {
|
|
|
|
return nil // Skip with no errors
|
|
|
|
}
|
|
|
|
|
|
|
|
dat, err := ioutil.ReadFile(currentpath)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Error reading file "+currentpath)
|
|
|
|
}
|
|
|
|
|
|
|
|
artifact, err := compiler.NewPackageArtifactFromYaml(dat)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Error reading yaml "+currentpath)
|
|
|
|
}
|
|
|
|
art = append(art, artifact)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err := filepath.Walk(path, ff)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
return art, nil
|
|
|
|
}
|
|
|
|
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) GetName() string {
|
|
|
|
return r.LuetRepository.Name
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) GetDescription() string {
|
|
|
|
return r.LuetRepository.Description
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
2020-01-28 16:46:32 +00:00
|
|
|
|
2020-02-02 23:58:55 +00:00
|
|
|
func (r *LuetSystemRepository) GetAuthentication() map[string]string {
|
|
|
|
return r.LuetRepository.Authentication
|
|
|
|
}
|
|
|
|
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) GetType() string {
|
|
|
|
return r.LuetRepository.Type
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) SetType(p string) {
|
|
|
|
r.LuetRepository.Type = p
|
2019-11-23 14:42:05 +00:00
|
|
|
}
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) AddUrl(p string) {
|
|
|
|
r.LuetRepository.Urls = append(r.LuetRepository.Urls, p)
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) GetUrls() []string {
|
|
|
|
return r.LuetRepository.Urls
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) SetUrls(urls []string) {
|
|
|
|
r.LuetRepository.Urls = urls
|
2019-11-25 19:02:59 +00:00
|
|
|
}
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) GetPriority() int {
|
|
|
|
return r.LuetRepository.Priority
|
2019-12-30 21:51:51 +00:00
|
|
|
}
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) GetTreePath() string {
|
|
|
|
return r.TreePath
|
|
|
|
}
|
|
|
|
func (r *LuetSystemRepository) SetTreePath(p string) {
|
|
|
|
r.TreePath = p
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
2020-03-23 22:56:29 +00:00
|
|
|
func (r *LuetSystemRepository) GetMetaPath() string {
|
|
|
|
return r.MetaPath
|
|
|
|
}
|
|
|
|
func (r *LuetSystemRepository) SetMetaPath(p string) {
|
|
|
|
r.MetaPath = p
|
|
|
|
}
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) SetTree(b tree.Builder) {
|
|
|
|
r.Tree = b
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) GetIndex() compiler.ArtifactIndex {
|
2019-11-22 20:01:38 +00:00
|
|
|
return r.Index
|
|
|
|
}
|
2020-03-23 22:56:29 +00:00
|
|
|
func (r *LuetSystemRepository) SetIndex(i compiler.ArtifactIndex) {
|
|
|
|
r.Index = i
|
|
|
|
}
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) GetTree() tree.Builder {
|
2019-11-22 20:01:38 +00:00
|
|
|
return r.Tree
|
|
|
|
}
|
2020-01-03 23:31:11 +00:00
|
|
|
func (r *LuetSystemRepository) GetRevision() int {
|
2020-02-02 23:58:55 +00:00
|
|
|
return r.LuetRepository.Revision
|
2020-01-03 23:31:11 +00:00
|
|
|
}
|
|
|
|
func (r *LuetSystemRepository) GetLastUpdate() string {
|
2020-02-02 23:58:55 +00:00
|
|
|
return r.LuetRepository.LastUpdate
|
2020-01-03 23:31:11 +00:00
|
|
|
}
|
|
|
|
func (r *LuetSystemRepository) SetLastUpdate(u string) {
|
2020-02-02 23:58:55 +00:00
|
|
|
r.LuetRepository.LastUpdate = u
|
2020-01-03 23:31:11 +00:00
|
|
|
}
|
|
|
|
func (r *LuetSystemRepository) IncrementRevision() {
|
2020-02-02 23:58:55 +00:00
|
|
|
r.LuetRepository.Revision++
|
|
|
|
}
|
|
|
|
func (r *LuetSystemRepository) SetAuthentication(auth map[string]string) {
|
|
|
|
r.LuetRepository.Authentication = auth
|
2020-01-03 23:31:11 +00:00
|
|
|
}
|
2020-03-23 22:56:29 +00:00
|
|
|
func (r *LuetSystemRepository) GetRepositoryFile(name string) (LuetRepositoryFile, error) {
|
|
|
|
ans, ok := r.RepositoryFiles[name]
|
|
|
|
if ok {
|
|
|
|
return ans, nil
|
|
|
|
}
|
|
|
|
return ans, errors.New("Repository file " + name + " not found!")
|
|
|
|
}
|
|
|
|
func (r *LuetSystemRepository) SetRepositoryFile(name string, f LuetRepositoryFile) {
|
|
|
|
r.RepositoryFiles[name] = f
|
|
|
|
}
|
2020-01-03 23:31:11 +00:00
|
|
|
|
|
|
|
func (r *LuetSystemRepository) ReadSpecFile(file string, removeFile bool) (Repository, error) {
|
|
|
|
dat, err := ioutil.ReadFile(file)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Error reading file "+file)
|
|
|
|
}
|
|
|
|
if removeFile {
|
|
|
|
defer os.Remove(file)
|
|
|
|
}
|
|
|
|
|
|
|
|
var repo Repository
|
|
|
|
repo, err = NewLuetSystemRepositoryFromYaml(dat, pkg.NewInMemoryDatabase(false))
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Error reading repository from file "+file)
|
|
|
|
}
|
|
|
|
|
2020-03-24 11:52:24 +00:00
|
|
|
// Check if mandatory key are present
|
|
|
|
_, err = repo.GetRepositoryFile(REPOFILE_TREE_KEY)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("Invalid repository without the " + REPOFILE_TREE_KEY + " key file.")
|
|
|
|
}
|
|
|
|
_, err = repo.GetRepositoryFile(REPOFILE_META_KEY)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("Invalid repository without the " + REPOFILE_META_KEY + " key file.")
|
|
|
|
}
|
|
|
|
|
2020-01-03 23:31:11 +00:00
|
|
|
return repo, err
|
|
|
|
}
|
2019-11-22 20:01:38 +00:00
|
|
|
|
2020-01-03 23:31:11 +00:00
|
|
|
func (r *LuetSystemRepository) Write(dst string, resetRevision bool) error {
|
2020-01-02 17:31:25 +00:00
|
|
|
err := os.MkdirAll(dst, os.ModePerm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-03 19:09:29 +00:00
|
|
|
r.LastUpdate = strconv.FormatInt(time.Now().Unix(), 10)
|
2020-01-03 23:31:11 +00:00
|
|
|
|
|
|
|
repospec := filepath.Join(dst, REPOSITORY_SPECFILE)
|
|
|
|
if resetRevision {
|
|
|
|
r.Revision = 0
|
|
|
|
} else {
|
|
|
|
if _, err := os.Stat(repospec); !os.IsNotExist(err) {
|
|
|
|
// Read existing file for retrieve revision
|
|
|
|
spec, err := r.ReadSpecFile(repospec, false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
r.Revision = spec.GetRevision()
|
|
|
|
}
|
|
|
|
}
|
2020-01-03 19:09:29 +00:00
|
|
|
r.Revision++
|
2019-11-29 18:01:59 +00:00
|
|
|
|
2020-01-03 23:31:11 +00:00
|
|
|
Info(fmt.Sprintf(
|
|
|
|
"For repository %s creating revision %d and last update %s...",
|
|
|
|
r.Name, r.Revision, r.LastUpdate,
|
|
|
|
))
|
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
// Create tree and repository file
|
2019-11-22 20:01:38 +00:00
|
|
|
archive, err := ioutil.TempDir(os.TempDir(), "archive")
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Error met while creating tempdir for archive")
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(archive) // clean up
|
|
|
|
err = r.GetTree().Save(archive)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Error met while saving the tree")
|
|
|
|
}
|
2020-03-23 22:56:29 +00:00
|
|
|
|
|
|
|
treeFile, err := r.GetRepositoryFile(REPOFILE_TREE_KEY)
|
|
|
|
if err != nil {
|
|
|
|
treeFile = NewDefaultTreeRepositoryFile()
|
|
|
|
r.SetRepositoryFile(REPOFILE_TREE_KEY, treeFile)
|
2020-01-28 16:46:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 17:30:52 +00:00
|
|
|
a := compiler.NewPackageArtifact(filepath.Join(dst, treeFile.GetFileName()))
|
2020-03-23 22:56:29 +00:00
|
|
|
a.SetCompressionType(treeFile.GetCompressionType())
|
2020-01-28 16:46:32 +00:00
|
|
|
err = a.Compress(archive, 1)
|
2019-11-22 20:01:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Error met while creating package archive")
|
|
|
|
}
|
2020-01-28 16:46:32 +00:00
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
// Update the tree name with the name created by compression selected.
|
2020-03-24 17:30:52 +00:00
|
|
|
treeFile.SetFileName(path.Base(a.GetPath()))
|
2020-01-28 16:46:32 +00:00
|
|
|
err = a.Hash()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Failed generating checksums for tree")
|
|
|
|
}
|
2020-03-23 22:56:29 +00:00
|
|
|
treeFile.SetChecksums(a.GetChecksums())
|
2020-03-23 23:31:41 +00:00
|
|
|
r.SetRepositoryFile(REPOFILE_TREE_KEY, treeFile)
|
2020-03-23 22:56:29 +00:00
|
|
|
|
|
|
|
// Create Metadata struct and serialized repository
|
|
|
|
meta, serialized := r.Serialize()
|
|
|
|
|
|
|
|
// Create metadata file and repository file
|
|
|
|
metaTmpDir, err := ioutil.TempDir(os.TempDir(), "metadata")
|
|
|
|
defer os.RemoveAll(metaTmpDir) // clean up
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Error met while creating tempdir for metadata")
|
|
|
|
}
|
|
|
|
|
|
|
|
metaFile, err := r.GetRepositoryFile(REPOFILE_META_KEY)
|
|
|
|
if err != nil {
|
|
|
|
metaFile = NewDefaultMetaRepositoryFile()
|
|
|
|
r.SetRepositoryFile(REPOFILE_META_KEY, metaFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
repoMetaSpec := filepath.Join(metaTmpDir, REPOSITORY_METAFILE)
|
|
|
|
// Create repository.meta.yaml file
|
|
|
|
err = meta.WriteFile(repoMetaSpec)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:30:52 +00:00
|
|
|
a = compiler.NewPackageArtifact(filepath.Join(dst, metaFile.GetFileName()))
|
2020-03-23 22:56:29 +00:00
|
|
|
a.SetCompressionType(metaFile.GetCompressionType())
|
|
|
|
err = a.Compress(metaTmpDir, 1)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Error met while archiving repository metadata")
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:30:52 +00:00
|
|
|
metaFile.SetFileName(path.Base(a.GetPath()))
|
2020-03-23 23:31:41 +00:00
|
|
|
r.SetRepositoryFile(REPOFILE_META_KEY, metaFile)
|
2020-03-23 22:56:29 +00:00
|
|
|
err = a.Hash()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Failed generating checksums for metadata")
|
|
|
|
}
|
|
|
|
metaFile.SetChecksums(a.GetChecksums())
|
2020-01-28 16:46:32 +00:00
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
data, err := yaml.Marshal(serialized)
|
2020-01-28 16:46:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = ioutil.WriteFile(repospec, data, os.ModePerm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-22 20:01:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-12-31 00:21:06 +00:00
|
|
|
func (r *LuetSystemRepository) Client() Client {
|
2019-11-22 22:12:03 +00:00
|
|
|
switch r.GetType() {
|
2019-12-27 19:12:08 +00:00
|
|
|
case "disk":
|
2019-12-30 21:51:51 +00:00
|
|
|
return client.NewLocalClient(client.RepoData{Urls: r.GetUrls()})
|
2019-11-26 17:05:41 +00:00
|
|
|
case "http":
|
2020-02-02 23:58:55 +00:00
|
|
|
return client.NewHttpClient(
|
|
|
|
client.RepoData{
|
|
|
|
Urls: r.GetUrls(),
|
|
|
|
Authentication: r.GetAuthentication(),
|
|
|
|
})
|
2019-11-22 22:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-01-12 22:31:43 +00:00
|
|
|
func (r *LuetSystemRepository) Sync(force bool) (Repository, error) {
|
|
|
|
var repoUpdated bool = false
|
2020-03-23 22:56:29 +00:00
|
|
|
var treefs, metafs string
|
2020-01-12 22:31:43 +00:00
|
|
|
|
|
|
|
Debug("Sync of the repository", r.Name, "in progress...")
|
2019-11-22 22:12:03 +00:00
|
|
|
c := r.Client()
|
2019-11-23 14:42:05 +00:00
|
|
|
if c == nil {
|
|
|
|
return nil, errors.New("No client could be generated from repository.")
|
|
|
|
}
|
2020-01-12 22:31:43 +00:00
|
|
|
|
|
|
|
// Retrieve remote repository.yaml for retrieve revision and date
|
2020-01-03 23:31:11 +00:00
|
|
|
file, err := c.DownloadFile(REPOSITORY_SPECFILE)
|
2019-11-22 20:01:38 +00:00
|
|
|
if err != nil {
|
2020-01-03 23:31:11 +00:00
|
|
|
return nil, errors.Wrap(err, "While downloading "+REPOSITORY_SPECFILE)
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
2020-01-12 22:31:43 +00:00
|
|
|
|
2020-02-12 09:20:07 +00:00
|
|
|
repobasedir := config.LuetCfg.GetSystem().GetRepoDatabaseDirPath(r.GetName())
|
2020-01-12 22:31:43 +00:00
|
|
|
repo, err := r.ReadSpecFile(file, false)
|
2019-11-22 20:01:38 +00:00
|
|
|
if err != nil {
|
2020-01-03 23:31:11 +00:00
|
|
|
return nil, err
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
2020-01-12 22:31:43 +00:00
|
|
|
// Remove temporary file that contains repository.html.
|
|
|
|
// Example: /tmp/HttpClient236052003
|
|
|
|
defer os.RemoveAll(file)
|
|
|
|
|
|
|
|
if r.Cached {
|
|
|
|
if !force {
|
|
|
|
localRepo, _ := r.ReadSpecFile(filepath.Join(repobasedir, REPOSITORY_SPECFILE), false)
|
|
|
|
if localRepo != nil {
|
|
|
|
if localRepo.GetRevision() == repo.GetRevision() &&
|
|
|
|
localRepo.GetLastUpdate() == repo.GetLastUpdate() {
|
|
|
|
repoUpdated = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if r.GetTreePath() == "" {
|
|
|
|
treefs = filepath.Join(repobasedir, "treefs")
|
|
|
|
} else {
|
|
|
|
treefs = r.GetTreePath()
|
|
|
|
}
|
2020-03-23 22:56:29 +00:00
|
|
|
if r.GetMetaPath() == "" {
|
|
|
|
metafs = filepath.Join(repobasedir, "metafs")
|
|
|
|
} else {
|
|
|
|
metafs = r.GetMetaPath()
|
|
|
|
}
|
2019-11-22 20:01:38 +00:00
|
|
|
|
2020-01-12 22:31:43 +00:00
|
|
|
} else {
|
|
|
|
treefs, err = ioutil.TempDir(os.TempDir(), "treefs")
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Error met while creating tempdir for rootfs")
|
|
|
|
}
|
2020-03-28 11:07:40 +00:00
|
|
|
// If we always remove them, later on, no other structure can access
|
|
|
|
// to the tree for e.g. to retrieve finalizers
|
|
|
|
//defer os.RemoveAll(treefs)
|
2020-03-23 22:56:29 +00:00
|
|
|
|
|
|
|
metafs, err = ioutil.TempDir(os.TempDir(), "metafs")
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Error met whilte creating tempdir for metafs")
|
|
|
|
}
|
2020-03-28 11:07:40 +00:00
|
|
|
//defer os.RemoveAll(metafs)
|
2020-03-23 22:56:29 +00:00
|
|
|
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
// POST: treeFile and metaFile are present. I check this inside
|
|
|
|
// ReadSpecFile and NewLuetSystemRepositoryFromYaml
|
|
|
|
treeFile, _ := repo.GetRepositoryFile(REPOFILE_TREE_KEY)
|
|
|
|
metaFile, _ := repo.GetRepositoryFile(REPOFILE_META_KEY)
|
|
|
|
|
2020-01-12 22:31:43 +00:00
|
|
|
if !repoUpdated {
|
2020-01-28 16:46:32 +00:00
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
// Get Tree
|
2020-03-24 17:30:52 +00:00
|
|
|
a := compiler.NewPackageArtifact(treeFile.GetFileName())
|
2020-03-23 22:56:29 +00:00
|
|
|
artifactTree, err := c.DownloadArtifact(a)
|
2020-01-12 22:31:43 +00:00
|
|
|
if err != nil {
|
2020-03-24 17:30:52 +00:00
|
|
|
return nil, errors.Wrap(err, "While downloading "+treeFile.GetFileName())
|
2020-01-28 16:46:32 +00:00
|
|
|
}
|
2020-03-23 22:56:29 +00:00
|
|
|
defer os.Remove(artifactTree.GetPath())
|
2020-01-28 16:46:32 +00:00
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
artifactTree.SetChecksums(treeFile.GetChecksums())
|
|
|
|
artifactTree.SetCompressionType(treeFile.GetCompressionType())
|
2020-01-28 16:46:32 +00:00
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
err = artifactTree.Verify()
|
2020-01-28 16:46:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Tree integrity check failure")
|
2020-01-12 22:31:43 +00:00
|
|
|
}
|
2019-11-22 20:01:38 +00:00
|
|
|
|
2020-01-12 22:31:43 +00:00
|
|
|
Debug("Tree tarball for the repository " + r.GetName() + " downloaded correctly.")
|
2019-11-22 20:01:38 +00:00
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
// Get Repository Metadata
|
2020-03-24 17:30:52 +00:00
|
|
|
a = compiler.NewPackageArtifact(metaFile.GetFileName())
|
2020-03-23 22:56:29 +00:00
|
|
|
artifactMeta, err := c.DownloadArtifact(a)
|
|
|
|
if err != nil {
|
2020-03-24 17:30:52 +00:00
|
|
|
return nil, errors.Wrap(err, "While downloading "+metaFile.GetFileName())
|
2020-03-23 22:56:29 +00:00
|
|
|
}
|
|
|
|
defer os.Remove(artifactMeta.GetPath())
|
|
|
|
|
|
|
|
artifactMeta.SetChecksums(metaFile.GetChecksums())
|
|
|
|
artifactMeta.SetCompressionType(metaFile.GetCompressionType())
|
|
|
|
|
|
|
|
err = artifactMeta.Verify()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Metadata integrity check failure")
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug("Metadata tarball for the repository " + r.GetName() + " downloaded correctly.")
|
|
|
|
|
2020-01-12 22:31:43 +00:00
|
|
|
if r.Cached {
|
|
|
|
// Copy updated repository.yaml file to repo dir now that the tree is synced.
|
|
|
|
err = helpers.CopyFile(file, filepath.Join(repobasedir, REPOSITORY_SPECFILE))
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Error on update "+REPOSITORY_SPECFILE)
|
|
|
|
}
|
|
|
|
// Remove previous tree
|
|
|
|
os.RemoveAll(treefs)
|
2020-03-23 22:56:29 +00:00
|
|
|
// Remove previous meta dir
|
|
|
|
os.RemoveAll(metafs)
|
2020-01-12 22:31:43 +00:00
|
|
|
}
|
2020-01-28 16:46:32 +00:00
|
|
|
Debug("Decompress tree of the repository " + r.Name + "...")
|
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
err = artifactTree.Unpack(treefs, true)
|
2020-01-12 22:31:43 +00:00
|
|
|
if err != nil {
|
2020-01-28 16:46:32 +00:00
|
|
|
return nil, errors.Wrap(err, "Error met while unpacking tree")
|
2020-01-12 22:31:43 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
// FIXME: It seems that tar with only one file doesn't create destination
|
|
|
|
// directory. I create directory directly for now.
|
|
|
|
os.MkdirAll(metafs, os.ModePerm)
|
|
|
|
err = artifactMeta.Unpack(metafs, true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Error met while unpacking metadata")
|
|
|
|
}
|
|
|
|
|
2020-01-12 22:31:43 +00:00
|
|
|
tsec, _ := strconv.ParseInt(repo.GetLastUpdate(), 10, 64)
|
|
|
|
|
|
|
|
InfoC(
|
|
|
|
Bold(Red(":house: Repository "+r.GetName()+" revision: ")).String() +
|
|
|
|
Bold(Green(repo.GetRevision())).String() + " - " +
|
|
|
|
Bold(Green(time.Unix(tsec, 0).String())).String(),
|
|
|
|
)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Info("Repository", r.GetName(), "is already up to date.")
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
meta, err := NewLuetSystemRepositoryMetadata(
|
|
|
|
filepath.Join(metafs, REPOSITORY_METAFILE), false,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "While processing "+REPOSITORY_METAFILE)
|
|
|
|
}
|
|
|
|
repo.SetIndex(meta.ToArtificatIndex())
|
|
|
|
|
2020-01-02 17:31:25 +00:00
|
|
|
reciper := tree.NewInstallerRecipe(pkg.NewInMemoryDatabase(false))
|
2019-11-22 20:01:38 +00:00
|
|
|
err = reciper.Load(treefs)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Error met while unpacking rootfs")
|
|
|
|
}
|
2020-01-12 22:31:43 +00:00
|
|
|
|
2019-11-23 14:42:05 +00:00
|
|
|
repo.SetTree(reciper)
|
2019-11-22 20:01:38 +00:00
|
|
|
repo.SetTreePath(treefs)
|
2019-12-30 21:51:51 +00:00
|
|
|
repo.SetUrls(r.GetUrls())
|
2020-02-02 23:58:55 +00:00
|
|
|
repo.SetAuthentication(r.GetAuthentication())
|
2019-11-22 20:01:38 +00:00
|
|
|
|
|
|
|
return repo, nil
|
|
|
|
}
|
|
|
|
|
2020-03-23 22:56:29 +00:00
|
|
|
func (r *LuetSystemRepository) Serialize() (*LuetSystemRepositoryMetadata, LuetSystemRepositorySerialized) {
|
|
|
|
|
|
|
|
serialized := LuetSystemRepositorySerialized{
|
|
|
|
Name: r.Name,
|
|
|
|
Description: r.Description,
|
|
|
|
Urls: r.Urls,
|
|
|
|
Priority: r.Priority,
|
|
|
|
Type: r.Type,
|
|
|
|
Revision: r.Revision,
|
|
|
|
LastUpdate: r.LastUpdate,
|
|
|
|
RepositoryFiles: r.RepositoryFiles,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if is needed set the index or simply use
|
|
|
|
// value returned by CleanPath
|
|
|
|
r.Index = r.Index.CleanPath()
|
|
|
|
|
|
|
|
meta := &LuetSystemRepositoryMetadata{
|
|
|
|
Index: []*compiler.PackageArtifact{},
|
|
|
|
}
|
|
|
|
for _, a := range r.Index {
|
|
|
|
art := a.(*compiler.PackageArtifact)
|
|
|
|
meta.Index = append(meta.Index, art)
|
|
|
|
}
|
|
|
|
|
|
|
|
return meta, serialized
|
|
|
|
}
|
|
|
|
|
2019-11-22 20:01:38 +00:00
|
|
|
func (r Repositories) Len() int { return len(r) }
|
|
|
|
func (r Repositories) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
|
|
|
|
func (r Repositories) Less(i, j int) bool {
|
|
|
|
return r[i].GetPriority() < r[j].GetPriority()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Repositories) World() []pkg.Package {
|
|
|
|
cache := map[string]pkg.Package{}
|
|
|
|
world := []pkg.Package{}
|
|
|
|
|
|
|
|
// Get Uniques. Walk in reverse so the definitions of most prio-repo overwrites lower ones
|
|
|
|
// In this way, when we will walk again later the deps sorting them by most higher prio we have better chance of success.
|
|
|
|
for i := len(r) - 1; i >= 0; i-- {
|
2019-11-29 18:01:52 +00:00
|
|
|
for _, p := range r[i].GetTree().GetDatabase().World() {
|
2019-11-22 20:01:38 +00:00
|
|
|
cache[p.GetFingerPrint()] = p
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range cache {
|
|
|
|
world = append(world, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return world
|
|
|
|
}
|
|
|
|
|
2019-11-29 18:01:52 +00:00
|
|
|
func (r Repositories) SyncDatabase(d pkg.PackageDatabase) {
|
|
|
|
cache := map[string]bool{}
|
|
|
|
|
|
|
|
// Get Uniques. Walk in reverse so the definitions of most prio-repo overwrites lower ones
|
|
|
|
// In this way, when we will walk again later the deps sorting them by most higher prio we have better chance of success.
|
|
|
|
for i := len(r) - 1; i >= 0; i-- {
|
|
|
|
for _, p := range r[i].GetTree().GetDatabase().World() {
|
|
|
|
if _, ok := cache[p.GetFingerPrint()]; !ok {
|
|
|
|
cache[p.GetFingerPrint()] = true
|
|
|
|
d.CreatePackage(p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-11-22 20:01:38 +00:00
|
|
|
type PackageMatch struct {
|
|
|
|
Repo Repository
|
|
|
|
Package pkg.Package
|
|
|
|
}
|
|
|
|
|
|
|
|
func (re Repositories) PackageMatches(p []pkg.Package) []PackageMatch {
|
|
|
|
// TODO: Better heuristic. here we pick the first repo that contains the atom, sorted by priority but
|
|
|
|
// we should do a permutations and get the best match, and in case there are more solutions the user should be able to pick
|
|
|
|
sort.Sort(re)
|
|
|
|
|
|
|
|
var matches []PackageMatch
|
|
|
|
PACKAGE:
|
|
|
|
for _, pack := range p {
|
|
|
|
for _, r := range re {
|
2019-11-29 18:01:52 +00:00
|
|
|
c, err := r.GetTree().GetDatabase().FindPackage(pack)
|
2019-11-22 20:01:38 +00:00
|
|
|
if err == nil {
|
|
|
|
matches = append(matches, PackageMatch{Package: c, Repo: r})
|
|
|
|
continue PACKAGE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches
|
|
|
|
|
|
|
|
}
|
2019-11-25 19:03:17 +00:00
|
|
|
|
2020-02-04 19:15:59 +00:00
|
|
|
func (re Repositories) ResolveSelectors(p []pkg.Package) []pkg.Package {
|
|
|
|
// If a selector is given, get the best from each repo
|
|
|
|
sort.Sort(re) // respect prio
|
|
|
|
var matches []pkg.Package
|
|
|
|
PACKAGE:
|
|
|
|
for _, pack := range p {
|
2020-02-17 16:20:52 +00:00
|
|
|
REPOSITORY:
|
2020-02-04 19:15:59 +00:00
|
|
|
for _, r := range re {
|
|
|
|
if pack.IsSelector() {
|
|
|
|
c, err := r.GetTree().GetDatabase().FindPackageCandidate(pack)
|
2020-02-17 16:20:52 +00:00
|
|
|
// If FindPackageCandidate returns the same package, it means it couldn't find one.
|
|
|
|
// Skip this repository and keep looking.
|
|
|
|
if c.String() == pack.String() {
|
|
|
|
continue REPOSITORY
|
|
|
|
}
|
2020-02-04 19:15:59 +00:00
|
|
|
if err == nil {
|
|
|
|
matches = append(matches, c)
|
|
|
|
continue PACKAGE
|
|
|
|
}
|
|
|
|
} else {
|
2020-02-17 16:20:52 +00:00
|
|
|
// If it's not a selector, just append it
|
2020-02-04 19:15:59 +00:00
|
|
|
matches = append(matches, pack)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-20 22:47:35 +00:00
|
|
|
func (re Repositories) SearchPackages(p string, o LuetSearchOpts) []PackageMatch {
|
2019-11-25 19:03:17 +00:00
|
|
|
sort.Sort(re)
|
|
|
|
var matches []PackageMatch
|
2020-03-20 22:47:35 +00:00
|
|
|
var err error
|
2019-11-25 19:03:17 +00:00
|
|
|
|
|
|
|
for _, r := range re {
|
2020-03-20 22:47:35 +00:00
|
|
|
var repoMatches []pkg.Package
|
|
|
|
|
2020-03-22 09:46:51 +00:00
|
|
|
switch o.Mode {
|
|
|
|
case SRegexPkg:
|
|
|
|
repoMatches, err = r.GetTree().GetDatabase().FindPackageMatch(p)
|
|
|
|
case SLabel:
|
2020-03-20 22:47:35 +00:00
|
|
|
repoMatches, err = r.GetTree().GetDatabase().FindPackageLabel(p)
|
2020-03-22 09:46:51 +00:00
|
|
|
case SRegexLabel:
|
2020-03-20 22:47:35 +00:00
|
|
|
repoMatches, err = r.GetTree().GetDatabase().FindPackageLabelMatch(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err == nil && len(repoMatches) > 0 {
|
|
|
|
for _, pack := range repoMatches {
|
2019-11-25 19:03:17 +00:00
|
|
|
matches = append(matches, PackageMatch{Package: pack, Repo: r})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches
|
|
|
|
}
|
2020-03-20 22:47:35 +00:00
|
|
|
|
|
|
|
func (re Repositories) SearchLabelMatch(s string) []PackageMatch {
|
|
|
|
return re.SearchPackages(s, LuetSearchOpts{Pattern: s, Mode: SRegexLabel})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (re Repositories) SearchLabel(s string) []PackageMatch {
|
|
|
|
return re.SearchPackages(s, LuetSearchOpts{Pattern: s, Mode: SLabel})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (re Repositories) Search(s string) []PackageMatch {
|
|
|
|
return re.SearchPackages(s, LuetSearchOpts{Pattern: s, Mode: SRegexPkg})
|
|
|
|
}
|