forked from Plemya-x/ALR
chore: refactor code
- remove legacy code - refactor search and add tests
This commit is contained in:
@ -77,7 +77,7 @@ func (rs *Repos) Pull(ctx context.Context, repos []types.Repo) error {
|
||||
}
|
||||
|
||||
slog.Info(gotext.Get("Pulling repository"), "name", repo.Name)
|
||||
repoDir := filepath.Join(config.GetPaths(ctx).RepoDir, repo.Name)
|
||||
repoDir := filepath.Join(rs.cfg.GetPaths(ctx).RepoDir, repo.Name)
|
||||
|
||||
var repoFS billy.Filesystem
|
||||
gitDir := filepath.Join(repoDir, ".git")
|
||||
@ -264,7 +264,7 @@ func (rs *Repos) processRepoChangesRunner(repoDir, scriptDir string) (*interp.Ru
|
||||
return interp.New(
|
||||
interp.Env(expand.ListEnviron(env...)),
|
||||
interp.ExecHandler(handlers.NopExec),
|
||||
interp.ReadDirHandler(handlers.RestrictedReadDir(repoDir)),
|
||||
interp.ReadDirHandler2(handlers.RestrictedReadDir(repoDir)),
|
||||
interp.StatHandler(handlers.RestrictedStat(repoDir)),
|
||||
interp.OpenHandler(handlers.RestrictedOpen(repoDir)),
|
||||
interp.StdIO(handlers.NopRWC{}, handlers.NopRWC{}, handlers.NopRWC{}),
|
||||
|
@ -1,60 +0,0 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 Евгений Храмов
|
||||
//
|
||||
// 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 3 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 repos
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
|
||||
database "gitea.plemya-x.ru/Plemya-x/ALR/internal/db"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
|
||||
)
|
||||
|
||||
// Pull pulls the provided repositories. If a repo doesn't exist, it will be cloned
|
||||
// and its packages will be written to the DB. If it does exist, it will be pulled.
|
||||
// In this case, only changed packages will be processed if possible.
|
||||
// If repos is set to nil, the repos in the ALR config will be used.
|
||||
//
|
||||
// Deprecated: use struct method
|
||||
func Pull(ctx context.Context, repos []types.Repo) error {
|
||||
return GetInstance(ctx).Pull(ctx, repos)
|
||||
}
|
||||
|
||||
// =======================
|
||||
// FOR LEGACY ONLY
|
||||
// =======================
|
||||
|
||||
var (
|
||||
reposInstance *Repos
|
||||
alrConfigOnce sync.Once
|
||||
)
|
||||
|
||||
// Deprecated: For legacy only
|
||||
func GetInstance(ctx context.Context) *Repos {
|
||||
alrConfigOnce.Do(func() {
|
||||
cfg := config.GetInstance(ctx)
|
||||
db := database.GetInstance(ctx)
|
||||
|
||||
reposInstance = New(
|
||||
cfg,
|
||||
db,
|
||||
)
|
||||
})
|
||||
|
||||
return reposInstance
|
||||
}
|
Reference in New Issue
Block a user