code cleanup

This commit is contained in:
Giovanni Harting 2023-06-05 15:33:02 +02:00
parent a04c17f6ab
commit db8cb28fc5
5 changed files with 22 additions and 21 deletions

View File

@ -27,6 +27,11 @@ linters-settings:
- '3'
- '4'
- '5'
- '6'
- '7'
- '8'
- '9'
- '10'
ignored-functions:
- strings.SplitN
- os.OpenFile
@ -47,7 +52,6 @@ linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- dupl
- errcheck

View File

@ -41,7 +41,9 @@ func (b *BuildManager) buildQueue(queue []*ProtoPackage, ctx context.Context) er
for len(doneQ) != len(queue) {
up := 0
b.buildingLock.RLock()
if (pkgList2MaxMem(b.building) < conf.Build.MemoryLimit && !unknownBuilds && !queueNoMatch) || (unknownBuilds && len(b.building) < MaxUnknownBuilder) {
if (pkgList2MaxMem(b.building) < conf.Build.MemoryLimit &&
!unknownBuilds && !queueNoMatch) ||
(unknownBuilds && len(b.building) < MaxUnknownBuilder) {
queueNoMatch = true
b.buildingLock.RUnlock()
for _, pkg := range queue {
@ -372,7 +374,7 @@ func (b *BuildManager) repoWorker(repo string) {
pkg.DBPackage = pkgUpd.SaveX(context.Background())
}
cmd = exec.Command("paccache", "-rc", filepath.Join(conf.Basedir.Repo, repo, "os", conf.Arch), "-k", "1")
cmd = exec.Command("paccache", "-rc", filepath.Join(conf.Basedir.Repo, repo, "os", conf.Arch), "-k", "1") //nolint:gosec
res, err = cmd.CombinedOutput()
log.Debug(string(res))
if err != nil {
@ -438,7 +440,7 @@ func (b *BuildManager) repoWorker(repo string) {
}
func (b *BuildManager) syncWorker(ctx context.Context) error {
err := os.MkdirAll(filepath.Join(conf.Basedir.Work), 0o755)
err := os.MkdirAll(conf.Basedir.Work, 0o755)
if err != nil {
log.Fatalf("error creating work dir %s: %v", conf.Basedir.Work, err)
}
@ -447,7 +449,7 @@ func (b *BuildManager) syncWorker(ctx context.Context) error {
gitPath := filepath.Join(conf.Basedir.Work, stateDir)
if _, err := os.Stat(gitPath); os.IsNotExist(err) {
cmd := exec.Command("git", "clone", "--depth=1", conf.StateRepo, gitPath)
cmd := exec.Command("git", "clone", "--depth=1", conf.StateRepo, gitPath) //nolint:gosec
res, err := cmd.CombinedOutput()
log.Debug(string(res))
if err != nil {

View File

@ -155,7 +155,11 @@ func housekeeping(repo, march string, wg *sync.WaitGroup) error {
}
if len(missingSplits) > 0 {
log.Infof("[HK] %s->%s missing split-package(s): %s", fullRepo, dbPkg.Pkgbase, missingSplits)
pkg.DBPackage, err = pkg.DBPackage.Update().ClearRepoVersion().ClearTagRev().SetStatus(dbpackage.StatusQueued).Save(context.Background())
pkg.DBPackage, err = pkg.DBPackage.Update().
ClearRepoVersion().
ClearTagRev().
SetStatus(dbpackage.StatusQueued).
Save(context.Background())
if err != nil {
return err
}

View File

@ -342,7 +342,7 @@ func (p *ProtoPackage) setupBuildDir() (string, error) {
gr = retry.WithMaxRetries(conf.MaxCloneRetries, gr)
if err := retry.Do(context.Background(), gr, func(ctx context.Context) error {
cmd := exec.Command("git", "clone", "--depth", "1", "--branch", p.State.TagVer,
cmd := exec.Command("git", "clone", "--depth", "1", "--branch", p.State.TagVer, //nolint:gosec
fmt.Sprintf("https://gitlab.archlinux.org/archlinux/packaging/packages/%s.git", gitlabPath), buildDir)
res, err := cmd.CombinedOutput()
log.Debug(string(res))
@ -452,7 +452,7 @@ func (p *ProtoPackage) isAvailable(h *alpm.Handle) bool {
} else if p.DBPackage != nil && len(p.DBPackage.Packages) > 0 {
pkg, err = dbs.FindSatisfier(p.DBPackage.Packages[0])
} else {
cmd := exec.Command("unbuffer", "pacsift", "--exact", "--base="+p.Pkgbase, "--repo="+p.Repo.String())
cmd := exec.Command("unbuffer", "pacsift", "--exact", "--base="+p.Pkgbase, "--repo="+p.Repo.String()) //nolint:gosec
var res []byte
res, err = cmd.CombinedOutput()
if err != nil {
@ -539,7 +539,6 @@ func (p *ProtoPackage) GitVersion(h *alpm.Handle) (string, error) {
return "", err
}
pkgloop:
for _, stateFile := range fStateFiles {
repo, _, _, err := stateFileMeta(stateFile)
if err != nil {
@ -548,7 +547,7 @@ func (p *ProtoPackage) GitVersion(h *alpm.Handle) (string, error) {
if iPackage.DB().Name() == repo {
fStateFiles = []string{stateFile}
break pkgloop
break
}
}
@ -589,7 +588,7 @@ func (p *ProtoPackage) genSrcinfo() error {
return nil
}
cmd := exec.Command("makepkg", "--printsrcinfo", "-p", filepath.Base(p.Pkgbuild))
cmd := exec.Command("makepkg", "--printsrcinfo", "-p", filepath.Base(p.Pkgbuild)) //nolint:gosec
cmd.Dir = filepath.Dir(p.Pkgbuild)
res, err := cmd.CombinedOutput()
if err != nil {

View File

@ -130,15 +130,6 @@ func statusID2string(s dbpackage.Status) string {
}
}
func containsSubStr(str string, subList []string) bool {
for _, checkStr := range subList {
if strings.Contains(str, checkStr) {
return true
}
}
return false
}
func cleanBuildDir(dir, chrootDir string) error {
if stat, err := os.Stat(dir); err == nil && stat.IsDir() {
err = os.RemoveAll(dir)
@ -376,7 +367,8 @@ func setupChroot() error {
return fmt.Errorf("error creating chroot: %w\n%s", err, string(res))
}
cmd = exec.Command("sudo", "cp", pacmanConf, filepath.Join(conf.Basedir.Work, chrootDir, pristineChroot, "etc/pacman.conf")) //nolint:gosec
cmd = exec.Command("sudo", "cp", pacmanConf, //nolint:gosec
filepath.Join(conf.Basedir.Work, chrootDir, pristineChroot, "etc/pacman.conf"))
res, err = cmd.CombinedOutput()
log.Debug(string(res))
if err != nil {