From 76b21b77701277c520cc1409a24e9bafed85ad7d Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Sat, 20 Nov 2021 01:02:37 +0100 Subject: [PATCH] check if package is available before build --- main.go | 14 ++++++++------ utils.go | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index c2c7f39..4f514e7 100644 --- a/main.go +++ b/main.go @@ -202,8 +202,12 @@ func (b *BuildManager) parseWorker() { } pkg.Version = constructVersion(pkg.Srcinfo.Pkgver, pkg.Srcinfo.Pkgrel, pkg.Srcinfo.Epoch) - pkg.toDbPackage(true) + if !pkg.isAvailable(alpmHandle) { + log.Debugf("[%s/%s] Not available on mirror, skipping build", pkg.FullRepo, pkg.Pkgbase) + continue + } + pkg.toDbPackage(true) skipping := false if contains(pkg.Srcinfo.Arch, "any") { log.Debugf("Skipped %s: any-Package", pkg.Srcinfo.Pkgbase) @@ -452,9 +456,7 @@ func (b *BuildManager) repoWorker(repo string) { res, err := cmd.CombinedOutput() log.Debug(string(res)) if err != nil && cmd.ProcessState.ExitCode() == 1 { - log.Debugf("Deleteing package %s failed: Package not found in database", pkg.Pkgbase) - b.repoWG.Done() - continue + log.Debugf("Deleting package %s failed: Package not found in repo-database", pkg.Pkgbase) } if pkg.DbPackage != nil { @@ -462,8 +464,8 @@ func (b *BuildManager) repoWorker(repo string) { } for _, file := range pkg.PkgFiles { - check(os.Remove(file)) - check(os.Remove(file + ".sig")) + _ = os.Remove(file) + _ = os.Remove(file + ".sig") } updateLastUpdated() b.repoWG.Done() diff --git a/utils.go b/utils.go index 5cc18ae..c3fee66 100644 --- a/utils.go +++ b/utils.go @@ -296,6 +296,26 @@ func initALPM(root string, dbpath string) (*alpm.Handle, error) { return h, nil } +func (p *BuildPackage) isAvailable(h *alpm.Handle) bool { + dbs, err := h.SyncDBs() + if err != nil { + return false + } + + buildManager.alpmMutex.Lock() + pkg, err := dbs.FindSatisfier(p.Srcinfo.Packages[0].Pkgname) + buildManager.alpmMutex.Unlock() + if err != nil { + return false + } + + if pkg.DB().Name() != p.Repo.String() { + return false + } + + return true +} + func (p *BuildPackage) SVN2GITVersion(h *alpm.Handle) (string, error) { if p.Pkgbuild == "" && p.Pkgbase == "" { return "", fmt.Errorf("invalid arguments") @@ -306,7 +326,7 @@ func (p *BuildPackage) SVN2GITVersion(h *alpm.Handle) (string, error) { var fPkgbuilds []string for _, pkgbuild := range pkgBuilds { - sPkgbuild := strings.Split(pkgbuild, "/") + sPkgbuild := strings.Split(pkgbuild, string(filepath.Separator)) repo := sPkgbuild[len(sPkgbuild)-2] if repo == "trunk" || containsSubStr(repo, conf.Blacklist.Repo) { @@ -325,7 +345,9 @@ func (p *BuildPackage) SVN2GITVersion(h *alpm.Handle) (string, error) { return "", err } + buildManager.alpmMutex.Lock() iPackage, err := dbs.FindSatisfier(p.Pkgbase) + buildManager.alpmMutex.Unlock() if err != nil { return "", err } @@ -490,8 +512,13 @@ func housekeeping(repo string, wg *sync.WaitGroup) error { pkgfile := PKGFile(path) dbPkg, err := pkgfile.DBPackage() if err != nil { - log.Warningf("[HK/%s] Unable to find entry for %s in db: %v", repo, filepath.Base(path), err) - // TODO: remove orphan file not tracked by db (WTF kmod-debug!) + log.Infof("[HK/%s] removing orphan %s", repo, filepath.Base(path)) + splitPath := strings.Split(path, string(filepath.Separator)) + pkg := &BuildPackage{ + FullRepo: splitPath[len(splitPath)-4], + PkgFiles: []string{path}, + } + buildManager.repoPurge[pkg.FullRepo] <- pkg continue } @@ -546,7 +573,9 @@ func housekeeping(repo string, wg *sync.WaitGroup) error { if err != nil { return err } + buildManager.alpmMutex.Lock() pkgResolved, err := dbs.FindSatisfier(dbPkg.Packages[0]) + buildManager.alpmMutex.Unlock() if err != nil || pkgResolved.DB().Name() != pkg.DbPackage.Repository.String() { // package not found on mirror/db -> not part of any repo anymore log.Infof("[HK/%s/%s] not part of repo", pkg.FullRepo, pkg.Pkgbase)