From 5f06ed99d01e7ad829e546c25514867dd39a0e13 Mon Sep 17 00:00:00 2001 From: Mustafa Gezen Date: Sun, 6 Nov 2022 04:59:44 +0100 Subject: [PATCH] Upgrade srpmproc to v0.4.2 Earlier srpmproc versions have a bug with VRE matching. The regex used to match the NVR was actually formed to match NVRA. This is generally not harmful, but NVRs that has an extra dot something in Release can throw off this regex into thinking that the dist is actually the arch. --- go.mod | 2 +- go.sum | 2 + .../rocky-linux/srpmproc/modulemd/modulemd.go | 1 + .../srpmproc/pkg/blob/file/file.go | 4 +- .../rocky-linux/srpmproc/pkg/blob/gcs/gcs.go | 3 +- .../rocky-linux/srpmproc/pkg/blob/s3/s3.go | 3 +- .../rocky-linux/srpmproc/pkg/data/import.go | 3 +- .../rocky-linux/srpmproc/pkg/data/process.go | 3 +- .../rocky-linux/srpmproc/pkg/data/utils.go | 5 +- .../srpmproc/pkg/directives/add.go | 4 +- .../srpmproc/pkg/directives/lookaside.go | 2 +- .../srpmproc/pkg/directives/patch.go | 1 + .../srpmproc/pkg/directives/replace.go | 2 +- .../srpmproc/pkg/directives/spec_change.go | 6 +- .../rocky-linux/srpmproc/pkg/misc/regex.go | 4 +- .../rocky-linux/srpmproc/pkg/modes/git.go | 7 +-- .../srpmproc/pkg/rpmutils/regex.go | 9 +-- .../srpmproc/pkg/srpmproc/fetch.go | 9 +-- .../srpmproc/pkg/srpmproc/patch.go | 5 +- .../srpmproc/pkg/srpmproc/process.go | 62 ++++++++----------- vendor/modules.txt | 2 +- 21 files changed, 65 insertions(+), 74 deletions(-) diff --git a/go.mod b/go.mod index 4ff9d5d..daab592 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( github.com/pelletier/go-toml v1.8.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_golang v1.13.0 - github.com/rocky-linux/srpmproc v0.4.1 + github.com/rocky-linux/srpmproc v0.4.2 github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.1.3 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 3f2dafe..920fdef 100644 --- a/go.sum +++ b/go.sum @@ -667,6 +667,8 @@ github.com/rocky-linux/srpmproc v0.3.16 h1:kxJEiQsZ0DcMhX0vY482n82XvjPiP2WifxI3N github.com/rocky-linux/srpmproc v0.3.16/go.mod h1:vWZzxPTfxh4pmfr5Mw20FyrqyKsbGHzDwOlN+W5EMpw= github.com/rocky-linux/srpmproc v0.4.1 h1:qcq7bGLplKbu+dSKQ9VBwcTao3OqPNb6rdKz58MCFLA= github.com/rocky-linux/srpmproc v0.4.1/go.mod h1:x8Z2wqhV2JqRnYMhYz3thOQkfsSWjJkyX8DVGDPOb48= +github.com/rocky-linux/srpmproc v0.4.2 h1:U8SnYPxYtJ2XIAnrcEvxx+PsHCi4uQsfIOIC754MKas= +github.com/rocky-linux/srpmproc v0.4.2/go.mod h1:x8Z2wqhV2JqRnYMhYz3thOQkfsSWjJkyX8DVGDPOb48= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= diff --git a/vendor/github.com/rocky-linux/srpmproc/modulemd/modulemd.go b/vendor/github.com/rocky-linux/srpmproc/modulemd/modulemd.go index 602b070..b7af2a4 100644 --- a/vendor/github.com/rocky-linux/srpmproc/modulemd/modulemd.go +++ b/vendor/github.com/rocky-linux/srpmproc/modulemd/modulemd.go @@ -22,6 +22,7 @@ package modulemd import ( "fmt" + "github.com/go-git/go-billy/v5" "gopkg.in/yaml.v3" ) diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/blob/file/file.go b/vendor/github.com/rocky-linux/srpmproc/pkg/blob/file/file.go index 97bf922..641cfa1 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/blob/file/file.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/blob/file/file.go @@ -38,7 +38,7 @@ func New(path string) *File { } func (f *File) Write(path string, content []byte) error { - w, err := os.OpenFile(filepath.Join(f.path, path), os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644) + w, err := os.OpenFile(filepath.Join(f.path, path), os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0o644) if err != nil { return fmt.Errorf("could not open file: %v", err) } @@ -57,7 +57,7 @@ func (f *File) Write(path string, content []byte) error { } func (f *File) Read(path string) ([]byte, error) { - r, err := os.OpenFile(filepath.Join(f.path, path), os.O_RDONLY, 0644) + r, err := os.OpenFile(filepath.Join(f.path, path), os.O_RDONLY, 0o644) if err != nil { if os.IsNotExist(err) { return nil, nil diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/blob/gcs/gcs.go b/vendor/github.com/rocky-linux/srpmproc/pkg/blob/gcs/gcs.go index 29f3eed..f897034 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/blob/gcs/gcs.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/blob/gcs/gcs.go @@ -21,10 +21,11 @@ package gcs import ( - "cloud.google.com/go/storage" "context" "fmt" "io/ioutil" + + "cloud.google.com/go/storage" ) type GCS struct { diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/blob/s3/s3.go b/vendor/github.com/rocky-linux/srpmproc/pkg/blob/s3/s3.go index a5701c2..1d475c1 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/blob/s3/s3.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/blob/s3/s3.go @@ -22,6 +22,8 @@ package s3 import ( "bytes" + "io/ioutil" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/credentials" @@ -29,7 +31,6 @@ import ( "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3manager" "github.com/spf13/viper" - "io/ioutil" ) type S3 struct { diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/data/import.go b/vendor/github.com/rocky-linux/srpmproc/pkg/data/import.go index 9f13778..da9694a 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/data/import.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/data/import.go @@ -21,8 +21,9 @@ package data import ( - "github.com/go-git/go-git/v5" "hash" + + "github.com/go-git/go-git/v5" ) type ImportMode interface { diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/data/process.go b/vendor/github.com/rocky-linux/srpmproc/pkg/data/process.go index 72d9a61..a3797a8 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/data/process.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/data/process.go @@ -21,10 +21,11 @@ package data import ( + "log" + "github.com/go-git/go-billy/v5" "github.com/go-git/go-git/v5/plumbing/transport" "github.com/rocky-linux/srpmproc/pkg/blob" - "log" ) type FsCreatorFunc func(branch string) (billy.Filesystem, error) diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/data/utils.go b/vendor/github.com/rocky-linux/srpmproc/pkg/data/utils.go index 9807aff..ffdd647 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/data/utils.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/data/utils.go @@ -27,11 +27,12 @@ import ( "crypto/sha512" "encoding/hex" "fmt" - "github.com/go-git/go-billy/v5" "hash" "io" "os" "path/filepath" + + "github.com/go-git/go-billy/v5" ) func CopyFromFs(from billy.Filesystem, to billy.Filesystem, path string) error { @@ -44,7 +45,7 @@ func CopyFromFs(from billy.Filesystem, to billy.Filesystem, path string) error { fullPath := filepath.Join(path, fi.Name()) if fi.IsDir() { - _ = to.MkdirAll(fullPath, 0755) + _ = to.MkdirAll(fullPath, 0o755) err := CopyFromFs(from, to, fullPath) if err != nil { return err diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/directives/add.go b/vendor/github.com/rocky-linux/srpmproc/pkg/directives/add.go index c7cdc12..079bb85 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/directives/add.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/directives/add.go @@ -50,7 +50,7 @@ func add(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, patchTree case *srpmprocpb.Add_File: filePath = checkAddPrefix(eitherString(filepath.Base(addType.File), add.Name)) - fPatch, err := patchTree.Filesystem.OpenFile(addType.File, os.O_RDONLY, 0644) + fPatch, err := patchTree.Filesystem.OpenFile(addType.File, os.O_RDONLY, 0o644) if err != nil { return errors.New(fmt.Sprintf("COULD_NOT_OPEN_FROM:%s", addType.File)) } @@ -80,7 +80,7 @@ func add(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, patchTree break } - f, err := pushTree.Filesystem.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) + f, err := pushTree.Filesystem.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644) if err != nil { return errors.New(fmt.Sprintf("COULD_NOT_OPEN_DESTINATION:%s", filePath)) } diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/directives/lookaside.go b/vendor/github.com/rocky-linux/srpmproc/pkg/directives/lookaside.go index 430183b..d8d4f59 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/directives/lookaside.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/directives/lookaside.go @@ -128,7 +128,7 @@ func lookaside(cfg *srpmprocpb.Cfg, _ *data.ProcessData, md *data.ModeData, patc } path := filepath.Join("SOURCES", fmt.Sprintf("%s.tar.gz", directive.ArchiveName)) - pushF, err := pushTree.Filesystem.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644) + pushF, err := pushTree.Filesystem.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0o644) if err != nil { return errors.New(fmt.Sprintf("COULD_NOT_CREATE_TAR_FILE:%s", path)) } diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/directives/patch.go b/vendor/github.com/rocky-linux/srpmproc/pkg/directives/patch.go index a0b2ccb..a2b562d 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/directives/patch.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/directives/patch.go @@ -24,6 +24,7 @@ import ( "bytes" "errors" "fmt" + "github.com/bluekeyes/go-gitdiff/gitdiff" "github.com/go-git/go-git/v5" srpmprocpb "github.com/rocky-linux/srpmproc/pb" diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/directives/replace.go b/vendor/github.com/rocky-linux/srpmproc/pkg/directives/replace.go index 2493d80..41d31d0 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/directives/replace.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/directives/replace.go @@ -51,7 +51,7 @@ func replace(cfg *srpmprocpb.Cfg, pd *data.ProcessData, _ *data.ModeData, patchT switch replacing := replace.Replacing.(type) { case *srpmprocpb.Replace_WithFile: - fPatch, err := patchTree.Filesystem.OpenFile(replacing.WithFile, os.O_RDONLY, 0644) + fPatch, err := patchTree.Filesystem.OpenFile(replacing.WithFile, os.O_RDONLY, 0o644) if err != nil { return errors.New(fmt.Sprintf("COULD_NOT_OPEN_REPLACING:%s", replacing.WithFile)) } diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/directives/spec_change.go b/vendor/github.com/rocky-linux/srpmproc/pkg/directives/spec_change.go index c0aac62..ea1152b 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/directives/spec_change.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/directives/spec_change.go @@ -41,9 +41,7 @@ const ( sectionChangelog = "%changelog" ) -var ( - sections = []string{"%description", "%prep", "%build", "%install", "%files", "%changelog"} -) +var sections = []string{"%description", "%prep", "%build", "%install", "%files", "%changelog"} type sourcePatchOperationInLoopRequest struct { cfg *srpmprocpb.Cfg @@ -212,7 +210,7 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _ return errors.New("COULD_NOT_STAT_SPEC_FILE") } - specFile, err := pushTree.Filesystem.OpenFile(filePath, os.O_RDONLY, 0644) + specFile, err := pushTree.Filesystem.OpenFile(filePath, os.O_RDONLY, 0o644) if err != nil { return errors.New("COULD_NOT_READ_SPEC_FILE") } diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/misc/regex.go b/vendor/github.com/rocky-linux/srpmproc/pkg/misc/regex.go index 3cc6f0b..6cb6e08 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/misc/regex.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/misc/regex.go @@ -2,10 +2,11 @@ package misc import ( "fmt" - "github.com/rocky-linux/srpmproc/pkg/data" "path/filepath" "regexp" "strings" + + "github.com/rocky-linux/srpmproc/pkg/data" ) func GetTagImportRegex(pd *data.ProcessData) *regexp.Regexp { @@ -37,7 +38,6 @@ func GetTagImportRegex(pd *data.ProcessData) *regexp.Regexp { // if we are ok with importing that reference. We are looking for the traditional pattern, like "c9s", and also the // modular "stream---rhel- branch pattern as well func TaglessRefOk(tag string, pd *data.ProcessData) bool { - // First case is very easy: if we are "refs/heads/" , then this is def. a branch we should import if strings.HasPrefix(tag, fmt.Sprintf("refs/heads/%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)) { return true diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/modes/git.go b/vendor/github.com/rocky-linux/srpmproc/pkg/modes/git.go index d68d7e4..f151aca 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/modes/git.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/modes/git.go @@ -22,8 +22,6 @@ package modes import ( "fmt" - "github.com/go-git/go-git/v5/plumbing/transport" - "github.com/rocky-linux/srpmproc/pkg/misc" "io/ioutil" "net/http" "path/filepath" @@ -31,6 +29,9 @@ import ( "strings" "time" + "github.com/go-git/go-git/v5/plumbing/transport" + "github.com/rocky-linux/srpmproc/pkg/misc" + "github.com/go-git/go-billy/v5/memfs" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/config" @@ -146,7 +147,6 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) { } tagIter, err := repo.TagObjects() - if err != nil { return nil, fmt.Errorf("could not get tag objects: %v", err) } @@ -221,7 +221,6 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) { } func (g *GitMode) WriteSource(pd *data.ProcessData, md *data.ModeData) error { - remote, err := md.Repo.Remote("upstream") if err != nil && !pd.TaglessMode { diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/rpmutils/regex.go b/vendor/github.com/rocky-linux/srpmproc/pkg/rpmutils/regex.go index ed711a3..477d7f8 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/rpmutils/regex.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/rpmutils/regex.go @@ -2,10 +2,5 @@ package rpmutils import "regexp" -var ( - Nvr = regexp.MustCompile("^(\\S+)-([\\w~%.+]+)-(\\w+(?:\\.[\\w+]+)+?)(?:\\.(\\w+))?(?:\\.rpm)?$") - epoch = regexp.MustCompile("(\\d+):") - module = regexp.MustCompile("^(.+)-(.+)-([0-9]{19})\\.((?:.+){8})$") - dist = regexp.MustCompile("(\\.el\\d(?:_\\d|))") - moduleDist = regexp.MustCompile("\\.module.+$") -) +// Nvr is a regular expression that matches a NVR. +var Nvr = regexp.MustCompile("^(\\S+)-([\\w~%.+]+)-(\\w+(?:\\.[\\w+]+)+?)(?:\\.rpm)?$") diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/fetch.go b/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/fetch.go index bbc4533..da7d0df 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/fetch.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/fetch.go @@ -3,15 +3,16 @@ package srpmproc import ( "errors" "fmt" - "github.com/go-git/go-billy/v5" - "github.com/rocky-linux/srpmproc/pkg/blob" - "github.com/rocky-linux/srpmproc/pkg/data" "io" "io/ioutil" "log" "net/http" "path/filepath" "strings" + + "github.com/go-git/go-billy/v5" + "github.com/rocky-linux/srpmproc/pkg/blob" + "github.com/rocky-linux/srpmproc/pkg/data" ) func Fetch(logger io.Writer, cdnUrl string, dir string, fs billy.Filesystem, storage blob.Storage) error { @@ -101,7 +102,7 @@ func Fetch(logger io.Writer, cdnUrl string, dir string, fs billy.Filesystem, sto return fmt.Errorf("checksum in metadata does not match dist-git file") } - err = fs.MkdirAll(filepath.Join(dir, filepath.Dir(path)), 0755) + err = fs.MkdirAll(filepath.Join(dir, filepath.Dir(path)), 0o755) if err != nil { return fmt.Errorf("could not create all directories") } diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/patch.go b/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/patch.go index 2baf2af..928d8ae 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/patch.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/patch.go @@ -23,8 +23,6 @@ package srpmproc import ( "encoding/json" "fmt" - "github.com/go-git/go-git/v5/plumbing/transport" - "github.com/rocky-linux/srpmproc/pkg/misc" "io/ioutil" "log" "os" @@ -32,6 +30,9 @@ import ( "strings" "time" + "github.com/go-git/go-git/v5/plumbing/transport" + "github.com/rocky-linux/srpmproc/pkg/misc" + "github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5/memfs" "github.com/go-git/go-git/v5" diff --git a/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/process.go b/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/process.go index de118ee..4712f74 100644 --- a/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/process.go +++ b/vendor/github.com/rocky-linux/srpmproc/pkg/srpmproc/process.go @@ -24,6 +24,16 @@ import ( "bufio" "encoding/hex" "fmt" + "io" + "io/ioutil" + "log" + "os" + "os/exec" + "os/user" + "path/filepath" + "strings" + "time" + "github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5/osfs" "github.com/go-git/go-git/v5/plumbing/format/gitignore" @@ -38,15 +48,6 @@ import ( "github.com/rocky-linux/srpmproc/pkg/misc" "github.com/rocky-linux/srpmproc/pkg/modes" "github.com/rocky-linux/srpmproc/pkg/rpmutils" - "io" - "io/ioutil" - "log" - "os" - "os/exec" - "os/user" - "path/filepath" - "strings" - "time" "github.com/go-git/go-billy/v5/memfs" "github.com/go-git/go-git/v5" @@ -227,7 +228,7 @@ func NewProcessData(req *ProcessDataRequest) (*data.ProcessData, error) { return nil, err } tmpDir := filepath.Join(req.TmpFsMode, branch) - err = fs.MkdirAll(tmpDir, 0755) + err = fs.MkdirAll(tmpDir, 0o755) if err != nil { return nil, fmt.Errorf("could not create tmpfs dir: %v", err) } @@ -287,7 +288,6 @@ func NewProcessData(req *ProcessDataRequest) (*data.ProcessData, error) { // all files that are remote goes into .gitignore // all ignored files' hash goes into .{Name}.metadata func ProcessRPM(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error) { - // if we are using "tagless mode", then we need to jump to a completely different import process: // Version info needs to be derived from rpmbuild + spec file, not tags if pd.TaglessMode { @@ -761,7 +761,7 @@ func processRPMTagless(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error if err := os.RemoveAll(localPath); err != nil { return nil, fmt.Errorf("Could not remove previous temporary directory: %s", localPath) } - if err := os.Mkdir(localPath, 0755); err != nil { + if err := os.Mkdir(localPath, 0o755); err != nil { return nil, fmt.Errorf("Could not create temporary directory: %s", localPath) } @@ -993,7 +993,6 @@ func processRPMTagless(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error BranchCommits: latestHashForBranch, BranchVersions: versionForBranch, }, nil - } // Given a local repo on disk, ensure it's in the "traditional" format. This means: @@ -1001,13 +1000,12 @@ func processRPMTagless(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error // - metadata file has the old " SOURCES/" format // - SPECS/ and SOURCES/ exist and are populated correctly func convertLocalRepo(pkgName string, localRepo string) (bool, error) { - // Make sure we have a SPECS and SOURCES folder made: - if err := os.MkdirAll(fmt.Sprintf("%s/SOURCES", localRepo), 0755); err != nil { + if err := os.MkdirAll(fmt.Sprintf("%s/SOURCES", localRepo), 0o755); err != nil { return false, fmt.Errorf("Could not create SOURCES directory in: %s", localRepo) } - if err := os.MkdirAll(fmt.Sprintf("%s/SPECS", localRepo), 0755); err != nil { + if err := os.MkdirAll(fmt.Sprintf("%s/SPECS", localRepo), 0o755); err != nil { return false, fmt.Errorf("Could not create SPECS directory in: %s", localRepo) } @@ -1017,15 +1015,14 @@ func convertLocalRepo(pkgName string, localRepo string) (bool, error) { return false, err } - for _, file := range files { - + for _, f := range files { // We don't want to process SOURCES, SPECS, or any of our .git folders - if file.Name() == "SOURCES" || file.Name() == "SPECS" || strings.HasPrefix(file.Name(), ".git") || file.Name() == "."+pkgName+".metadata" { + if f.Name() == "SOURCES" || f.Name() == "SPECS" || strings.HasPrefix(f.Name(), ".git") || f.Name() == "."+pkgName+".metadata" { continue } // If we have a metadata "sources" file, we need to read it and convert to the old ..metadata format - if file.Name() == "sources" { + if f.Name() == "sources" { convertStatus := convertMetaData(pkgName, localRepo) if convertStatus != true { @@ -1036,15 +1033,15 @@ func convertLocalRepo(pkgName string, localRepo string) (bool, error) { } // Any file that ends in a ".spec" should be put into SPECS/ - if strings.HasSuffix(file.Name(), ".spec") { - err := os.Rename(fmt.Sprintf("%s/%s", localRepo, file.Name()), fmt.Sprintf("%s/SPECS/%s", localRepo, file.Name())) + if strings.HasSuffix(f.Name(), ".spec") { + err := os.Rename(fmt.Sprintf("%s/%s", localRepo, f.Name()), fmt.Sprintf("%s/SPECS/%s", localRepo, f.Name())) if err != nil { return false, fmt.Errorf("Error moving .spec file to SPECS/") } } // if a file isn't skipped in one of the above checks, then it must be a file that belongs in SOURCES/ - os.Rename(fmt.Sprintf("%s/%s", localRepo, file.Name()), fmt.Sprintf("%s/SOURCES/%s", localRepo, file.Name())) + os.Rename(fmt.Sprintf("%s/%s", localRepo, f.Name()), fmt.Sprintf("%s/SOURCES/%s", localRepo, f.Name())) } return true, nil @@ -1053,7 +1050,6 @@ func convertLocalRepo(pkgName string, localRepo string) (bool, error) { // Given a local "sources" metadata file (new CentOS Stream format), convert it into the older // classic CentOS style: " SOURCES/" func convertMetaData(pkgName string, localRepo string) bool { - lookAside, err := os.Open(fmt.Sprintf("%s/sources", localRepo)) if err != nil { return false @@ -1072,7 +1068,6 @@ func convertMetaData(pkgName string, localRepo string) bool { // - take the // Then check for scanner.Scan() { - tmpLine := strings.Fields(scanner.Text()) // make sure line starts with a "SHA" or "MD" before processing - otherwise it might not be a valid format lookaside line! if !(strings.HasPrefix(tmpLine[0], "SHA") || strings.HasPrefix(tmpLine[0], "MD")) { @@ -1085,12 +1080,11 @@ func convertMetaData(pkgName string, localRepo string) bool { tmpLine[1] = fmt.Sprintf("SOURCES/%s", tmpLine[1]) convertedLA = append(convertedLA, fmt.Sprintf("%s %s", tmpLine[3], tmpLine[1])) - } lookAside.Close() // open ..metadata file for writing our old-format lines - lookAside, err = os.OpenFile(fmt.Sprintf("%s/.%s.metadata", localRepo, pkgName), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + lookAside, err = os.OpenFile(fmt.Sprintf("%s/.%s.metadata", localRepo, pkgName), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) if err != nil { fmt.Errorf("Error opening new .metadata file for writing.") return false @@ -1116,7 +1110,6 @@ func convertMetaData(pkgName string, localRepo string) bool { // - extract RPM version info from that SRPM, and return it // If we are in tagless mode, we need to get a package version somehow! func getVersionFromSpec(pkgName string, localRepo string, majorVersion int) string { - // Make sure we have "rpm" and "rpmbuild" and "cp" available in our PATH. Otherwise, this won't work: _, err := exec.LookPath("rpm") if err != nil { @@ -1135,7 +1128,7 @@ func getVersionFromSpec(pkgName string, localRepo string, majorVersion int) stri // create separate temp folder space to do our RPM work - we don't want to accidentally contaminate the main Git area: rpmBuildPath := fmt.Sprintf("%s_rpm", localRepo) - os.Mkdir(rpmBuildPath, 0755) + os.Mkdir(rpmBuildPath, 0o755) // Copy SOURCES/ and SPECS/ into the temp rpmbuild directory recursively // Yes, we could create or import an elaborate Go-native way to do this, but damnit this is easier: @@ -1165,7 +1158,7 @@ func getVersionFromSpec(pkgName string, localRepo string, majorVersion int) stri srcFile := strings.Fields(scanner.Text())[1] // write a dummy file of the same name into the rpmbuild SOURCES/ directory: - dummyFile, err := os.OpenFile(fmt.Sprintf("%s/%s", rpmBuildPath, srcFile), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + dummyFile, err := os.OpenFile(fmt.Sprintf("%s/%s", rpmBuildPath, srcFile), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) if err != nil { return "" } @@ -1222,7 +1215,6 @@ func getVersionFromSpec(pkgName string, localRepo string, majorVersion int) stri // return name-version-release string we derived: log.Printf("Derived NVR %s from tagless repo via temporary SRPM build\n", nvr) return nvr - } // We need to loop through the lookaside blob files ("SourcesToIgnore"), @@ -1230,7 +1222,6 @@ func getVersionFromSpec(pkgName string, localRepo string, majorVersion int) stri // // We also need to add the source paths to .gitignore in the git repo, so we don't accidentally commit + push them func processLookasideSources(pd *data.ProcessData, md *data.ModeData, localDir string) error { - w := md.Worktree metadata, err := w.Filesystem.Create(fmt.Sprintf(".%s.metadata", md.Name)) if err != nil { @@ -1240,7 +1231,7 @@ func processLookasideSources(pd *data.ProcessData, md *data.ModeData, localDir s // Keep track of files we've already uploaded - don't want duplicates! var alreadyUploadedBlobs []string - gitIgnore, err := os.OpenFile(fmt.Sprintf("%s/.gitignore", localDir), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + gitIgnore, err := os.OpenFile(fmt.Sprintf("%s/.gitignore", localDir), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) if err != nil { return err } @@ -1307,13 +1298,11 @@ func processLookasideSources(pd *data.ProcessData, md *data.ModeData, localDir s } return nil - } // Given an input branch name to import from, like "refs/heads/c9s", produce the tagless branch name we want to commit to, like "r9s" // Modular translation of CentOS stream branches i is also done - branch stream-maven-3.8-rhel-9.1.0 ----> r9s-stream-maven-3.8_9.1.0 func taglessBranchName(fullBranch string, pd *data.ProcessData) string { - // Split the full branch name "refs/heads/blah" to only get the short name - last entry tmpBranch := strings.Split(fullBranch, "/") branch := tmpBranch[len(tmpBranch)-1] @@ -1330,9 +1319,8 @@ func taglessBranchName(fullBranch string, pd *data.ProcessData) string { moduleString := branch[0:rhelSpot] // major minor version is everything after the "-rhel-" string - majorMinor := branch[rhelSpot+6 : len(branch)] + majorMinor := branch[rhelSpot+6:] // return translated modular branch: return fmt.Sprintf("%s%d%s-%s_%s", pd.BranchPrefix, pd.Version, pd.BranchSuffix, moduleString, majorMinor) - } diff --git a/vendor/modules.txt b/vendor/modules.txt index aa93bce..4c87081 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -453,7 +453,7 @@ github.com/prometheus/procfs/internal/util github.com/rivo/uniseg # github.com/robfig/cron v1.2.0 github.com/robfig/cron -# github.com/rocky-linux/srpmproc v0.4.1 +# github.com/rocky-linux/srpmproc v0.4.2 ## explicit github.com/rocky-linux/srpmproc/modulemd github.com/rocky-linux/srpmproc/pb