Formatting

This commit is contained in:
Mustafa Gezen 2022-11-06 04:53:02 +01:00
parent e859f54e5e
commit 2a2b10ba10
Signed by: mustafa
GPG Key ID: DCDF010D946438C1
20 changed files with 65 additions and 75 deletions

View File

@ -21,11 +21,12 @@
package main package main
import ( import (
"log"
"os"
"github.com/go-git/go-billy/v5/osfs" "github.com/go-git/go-billy/v5/osfs"
"github.com/rocky-linux/srpmproc/pkg/srpmproc" "github.com/rocky-linux/srpmproc/pkg/srpmproc"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"log"
"os"
) )
var fetch = &cobra.Command{ var fetch = &cobra.Command{

View File

@ -22,10 +22,11 @@ package main
import ( import (
"encoding/json" "encoding/json"
"github.com/rocky-linux/srpmproc/pkg/srpmproc"
"log" "log"
"os" "os"
"github.com/rocky-linux/srpmproc/pkg/srpmproc"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -97,7 +98,6 @@ func mn(_ *cobra.Command, _ []string) {
TaglessMode: taglessMode, TaglessMode: taglessMode,
AltLookAside: altLookAside, AltLookAside: altLookAside,
}) })
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -111,7 +111,6 @@ func mn(_ *cobra.Command, _ []string) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }
func main() { func main() {

View File

@ -22,6 +22,7 @@ package modulemd
import ( import (
"fmt" "fmt"
"github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )

View File

@ -38,7 +38,7 @@ func New(path string) *File {
} }
func (f *File) Write(path string, content []byte) error { 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 { if err != nil {
return fmt.Errorf("could not open file: %v", err) 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) { 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 err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil, nil return nil, nil

View File

@ -21,10 +21,11 @@
package gcs package gcs
import ( import (
"cloud.google.com/go/storage"
"context" "context"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"cloud.google.com/go/storage"
) )
type GCS struct { type GCS struct {

View File

@ -22,6 +22,8 @@ package s3
import ( import (
"bytes" "bytes"
"io/ioutil"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials" "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"
"github.com/aws/aws-sdk-go/service/s3/s3manager" "github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/spf13/viper" "github.com/spf13/viper"
"io/ioutil"
) )
type S3 struct { type S3 struct {

View File

@ -21,8 +21,9 @@
package data package data
import ( import (
"github.com/go-git/go-git/v5"
"hash" "hash"
"github.com/go-git/go-git/v5"
) )
type ImportMode interface { type ImportMode interface {

View File

@ -21,10 +21,11 @@
package data package data
import ( import (
"log"
"github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5"
"github.com/go-git/go-git/v5/plumbing/transport" "github.com/go-git/go-git/v5/plumbing/transport"
"github.com/rocky-linux/srpmproc/pkg/blob" "github.com/rocky-linux/srpmproc/pkg/blob"
"log"
) )
type FsCreatorFunc func(branch string) (billy.Filesystem, error) type FsCreatorFunc func(branch string) (billy.Filesystem, error)

View File

@ -27,11 +27,12 @@ import (
"crypto/sha512" "crypto/sha512"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/go-git/go-billy/v5"
"hash" "hash"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"github.com/go-git/go-billy/v5"
) )
func CopyFromFs(from billy.Filesystem, to billy.Filesystem, path string) error { 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()) fullPath := filepath.Join(path, fi.Name())
if fi.IsDir() { if fi.IsDir() {
_ = to.MkdirAll(fullPath, 0755) _ = to.MkdirAll(fullPath, 0o755)
err := CopyFromFs(from, to, fullPath) err := CopyFromFs(from, to, fullPath)
if err != nil { if err != nil {
return err return err

View File

@ -50,7 +50,7 @@ func add(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, patchTree
case *srpmprocpb.Add_File: case *srpmprocpb.Add_File:
filePath = checkAddPrefix(eitherString(filepath.Base(addType.File), add.Name)) 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 { if err != nil {
return errors.New(fmt.Sprintf("COULD_NOT_OPEN_FROM:%s", addType.File)) 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 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 { if err != nil {
return errors.New(fmt.Sprintf("COULD_NOT_OPEN_DESTINATION:%s", filePath)) return errors.New(fmt.Sprintf("COULD_NOT_OPEN_DESTINATION:%s", filePath))
} }

View File

@ -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)) 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 { if err != nil {
return errors.New(fmt.Sprintf("COULD_NOT_CREATE_TAR_FILE:%s", path)) return errors.New(fmt.Sprintf("COULD_NOT_CREATE_TAR_FILE:%s", path))
} }

View File

@ -24,6 +24,7 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/bluekeyes/go-gitdiff/gitdiff" "github.com/bluekeyes/go-gitdiff/gitdiff"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
srpmprocpb "github.com/rocky-linux/srpmproc/pb" srpmprocpb "github.com/rocky-linux/srpmproc/pb"

View File

@ -51,7 +51,7 @@ func replace(cfg *srpmprocpb.Cfg, pd *data.ProcessData, _ *data.ModeData, patchT
switch replacing := replace.Replacing.(type) { switch replacing := replace.Replacing.(type) {
case *srpmprocpb.Replace_WithFile: 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 { if err != nil {
return errors.New(fmt.Sprintf("COULD_NOT_OPEN_REPLACING:%s", replacing.WithFile)) return errors.New(fmt.Sprintf("COULD_NOT_OPEN_REPLACING:%s", replacing.WithFile))
} }

View File

@ -41,9 +41,7 @@ const (
sectionChangelog = "%changelog" sectionChangelog = "%changelog"
) )
var ( var sections = []string{"%description", "%prep", "%build", "%install", "%files", "%changelog"}
sections = []string{"%description", "%prep", "%build", "%install", "%files", "%changelog"}
)
type sourcePatchOperationInLoopRequest struct { type sourcePatchOperationInLoopRequest struct {
cfg *srpmprocpb.Cfg 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") 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 { if err != nil {
return errors.New("COULD_NOT_READ_SPEC_FILE") return errors.New("COULD_NOT_READ_SPEC_FILE")
} }

View File

@ -2,10 +2,11 @@ package misc
import ( import (
"fmt" "fmt"
"github.com/rocky-linux/srpmproc/pkg/data"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
"github.com/rocky-linux/srpmproc/pkg/data"
) )
func GetTagImportRegex(pd *data.ProcessData) *regexp.Regexp { 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 <prefix><version><suffix> pattern, like "c9s", and also the // if we are ok with importing that reference. We are looking for the traditional <prefix><version><suffix> pattern, like "c9s", and also the
// modular "stream-<NAME>-<VERSION>-rhel-<VERSION> branch pattern as well // modular "stream-<NAME>-<VERSION>-rhel-<VERSION> branch pattern as well
func TaglessRefOk(tag string, pd *data.ProcessData) bool { func TaglessRefOk(tag string, pd *data.ProcessData) bool {
// First case is very easy: if we are "refs/heads/<prefix><version><suffix>" , then this is def. a branch we should import // First case is very easy: if we are "refs/heads/<prefix><version><suffix>" , 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)) { if strings.HasPrefix(tag, fmt.Sprintf("refs/heads/%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)) {
return true return true

View File

@ -22,8 +22,6 @@ package modes
import ( import (
"fmt" "fmt"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/rocky-linux/srpmproc/pkg/misc"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"path/filepath" "path/filepath"
@ -31,6 +29,9 @@ import (
"strings" "strings"
"time" "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-billy/v5/memfs"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config" "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() tagIter, err := repo.TagObjects()
if err != nil { if err != nil {
return nil, fmt.Errorf("could not get tag objects: %v", err) 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 { func (g *GitMode) WriteSource(pd *data.ProcessData, md *data.ModeData) error {
remote, err := md.Repo.Remote("upstream") remote, err := md.Repo.Remote("upstream")
if err != nil && !pd.TaglessMode { if err != nil && !pd.TaglessMode {

View File

@ -3,9 +3,5 @@ package rpmutils
import "regexp" import "regexp"
var ( var (
Nvr = regexp.MustCompile("^(\\S+)-([\\w~%.+]+)-(\\w+(?:\\.[\\w+]+)+?)(?:\\.(\\w+))?(?:\\.rpm)?$") 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.+$")
) )

View File

@ -3,15 +3,16 @@ package srpmproc
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/go-git/go-billy/v5"
"github.com/rocky-linux/srpmproc/pkg/blob"
"github.com/rocky-linux/srpmproc/pkg/data"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"path/filepath" "path/filepath"
"strings" "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 { 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") 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 { if err != nil {
return fmt.Errorf("could not create all directories") return fmt.Errorf("could not create all directories")
} }

View File

@ -23,8 +23,6 @@ package srpmproc
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/rocky-linux/srpmproc/pkg/misc"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
@ -32,6 +30,9 @@ import (
"strings" "strings"
"time" "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"
"github.com/go-git/go-billy/v5/memfs" "github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"

View File

@ -24,6 +24,16 @@ import (
"bufio" "bufio"
"encoding/hex" "encoding/hex"
"fmt" "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"
"github.com/go-git/go-billy/v5/osfs" "github.com/go-git/go-billy/v5/osfs"
"github.com/go-git/go-git/v5/plumbing/format/gitignore" "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/misc"
"github.com/rocky-linux/srpmproc/pkg/modes" "github.com/rocky-linux/srpmproc/pkg/modes"
"github.com/rocky-linux/srpmproc/pkg/rpmutils" "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-billy/v5/memfs"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
@ -227,7 +228,7 @@ func NewProcessData(req *ProcessDataRequest) (*data.ProcessData, error) {
return nil, err return nil, err
} }
tmpDir := filepath.Join(req.TmpFsMode, branch) tmpDir := filepath.Join(req.TmpFsMode, branch)
err = fs.MkdirAll(tmpDir, 0755) err = fs.MkdirAll(tmpDir, 0o755)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not create tmpfs dir: %v", err) 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 files that are remote goes into .gitignore
// all ignored files' hash goes into .{Name}.metadata // all ignored files' hash goes into .{Name}.metadata
func ProcessRPM(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error) { 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: // 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 // Version info needs to be derived from rpmbuild + spec file, not tags
if pd.TaglessMode { if pd.TaglessMode {
@ -761,7 +761,7 @@ func processRPMTagless(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error
if err := os.RemoveAll(localPath); err != nil { if err := os.RemoveAll(localPath); err != nil {
return nil, fmt.Errorf("Could not remove previous temporary directory: %s", localPath) 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) 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, BranchCommits: latestHashForBranch,
BranchVersions: versionForBranch, BranchVersions: versionForBranch,
}, nil }, nil
} }
// Given a local repo on disk, ensure it's in the "traditional" format. This means: // 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 "<SHASUM> SOURCES/<filename>" format // - metadata file has the old "<SHASUM> SOURCES/<filename>" format
// - SPECS/ and SOURCES/ exist and are populated correctly // - SPECS/ and SOURCES/ exist and are populated correctly
func convertLocalRepo(pkgName string, localRepo string) (bool, error) { func convertLocalRepo(pkgName string, localRepo string) (bool, error) {
// Make sure we have a SPECS and SOURCES folder made: // 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) 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) 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 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 // 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 continue
} }
// If we have a metadata "sources" file, we need to read it and convert to the old .<pkgname>.metadata format // If we have a metadata "sources" file, we need to read it and convert to the old .<pkgname>.metadata format
if file.Name() == "sources" { if f.Name() == "sources" {
convertStatus := convertMetaData(pkgName, localRepo) convertStatus := convertMetaData(pkgName, localRepo)
if convertStatus != true { 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/ // Any file that ends in a ".spec" should be put into SPECS/
if strings.HasSuffix(file.Name(), ".spec") { if strings.HasSuffix(f.Name(), ".spec") {
err := os.Rename(fmt.Sprintf("%s/%s", localRepo, file.Name()), fmt.Sprintf("%s/SPECS/%s", localRepo, file.Name())) err := os.Rename(fmt.Sprintf("%s/%s", localRepo, f.Name()), fmt.Sprintf("%s/SPECS/%s", localRepo, f.Name()))
if err != nil { if err != nil {
return false, fmt.Errorf("Error moving .spec file to SPECS/") 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/ // 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 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 // Given a local "sources" metadata file (new CentOS Stream format), convert it into the older
// classic CentOS style: "<HASH> SOURCES/<FILENAME>" // classic CentOS style: "<HASH> SOURCES/<FILENAME>"
func convertMetaData(pkgName string, localRepo string) bool { func convertMetaData(pkgName string, localRepo string) bool {
lookAside, err := os.Open(fmt.Sprintf("%s/sources", localRepo)) lookAside, err := os.Open(fmt.Sprintf("%s/sources", localRepo))
if err != nil { if err != nil {
return false return false
@ -1072,7 +1068,6 @@ func convertMetaData(pkgName string, localRepo string) bool {
// - take the // - take the
// Then check // Then check
for scanner.Scan() { for scanner.Scan() {
tmpLine := strings.Fields(scanner.Text()) 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! // 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")) { 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]) tmpLine[1] = fmt.Sprintf("SOURCES/%s", tmpLine[1])
convertedLA = append(convertedLA, fmt.Sprintf("%s %s", tmpLine[3], tmpLine[1])) convertedLA = append(convertedLA, fmt.Sprintf("%s %s", tmpLine[3], tmpLine[1]))
} }
lookAside.Close() lookAside.Close()
// open .<NAME>.metadata file for writing our old-format lines // open .<NAME>.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 { if err != nil {
fmt.Errorf("Error opening new .metadata file for writing.") fmt.Errorf("Error opening new .metadata file for writing.")
return false return false
@ -1116,7 +1110,6 @@ func convertMetaData(pkgName string, localRepo string) bool {
// - extract RPM version info from that SRPM, and return it // - extract RPM version info from that SRPM, and return it
// If we are in tagless mode, we need to get a package version somehow! // If we are in tagless mode, we need to get a package version somehow!
func getVersionFromSpec(pkgName string, localRepo string, majorVersion int) string { 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: // Make sure we have "rpm" and "rpmbuild" and "cp" available in our PATH. Otherwise, this won't work:
_, err := exec.LookPath("rpm") _, err := exec.LookPath("rpm")
if err != nil { 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: // 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) rpmBuildPath := fmt.Sprintf("%s_rpm", localRepo)
os.Mkdir(rpmBuildPath, 0755) os.Mkdir(rpmBuildPath, 0o755)
// Copy SOURCES/ and SPECS/ into the temp rpmbuild directory recursively // 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: // 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] srcFile := strings.Fields(scanner.Text())[1]
// write a dummy file of the same name into the rpmbuild SOURCES/ directory: // 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 { if err != nil {
return "" return ""
} }
@ -1222,7 +1215,6 @@ func getVersionFromSpec(pkgName string, localRepo string, majorVersion int) stri
// return name-version-release string we derived: // return name-version-release string we derived:
log.Printf("Derived NVR %s from tagless repo via temporary SRPM build\n", nvr) log.Printf("Derived NVR %s from tagless repo via temporary SRPM build\n", nvr)
return nvr return nvr
} }
// We need to loop through the lookaside blob files ("SourcesToIgnore"), // 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 // 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 { func processLookasideSources(pd *data.ProcessData, md *data.ModeData, localDir string) error {
w := md.Worktree w := md.Worktree
metadata, err := w.Filesystem.Create(fmt.Sprintf(".%s.metadata", md.Name)) metadata, err := w.Filesystem.Create(fmt.Sprintf(".%s.metadata", md.Name))
if err != nil { 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! // Keep track of files we've already uploaded - don't want duplicates!
var alreadyUploadedBlobs []string 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 { if err != nil {
return err return err
} }
@ -1307,13 +1298,11 @@ func processLookasideSources(pd *data.ProcessData, md *data.ModeData, localDir s
} }
return nil 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" // 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 // 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 { func taglessBranchName(fullBranch string, pd *data.ProcessData) string {
// Split the full branch name "refs/heads/blah" to only get the short name - last entry // Split the full branch name "refs/heads/blah" to only get the short name - last entry
tmpBranch := strings.Split(fullBranch, "/") tmpBranch := strings.Split(fullBranch, "/")
branch := tmpBranch[len(tmpBranch)-1] branch := tmpBranch[len(tmpBranch)-1]
@ -1330,9 +1319,8 @@ func taglessBranchName(fullBranch string, pd *data.ProcessData) string {
moduleString := branch[0:rhelSpot] moduleString := branch[0:rhelSpot]
// major minor version is everything after the "-rhel-" string // major minor version is everything after the "-rhel-" string
majorMinor := branch[rhelSpot+6 : len(branch)] majorMinor := branch[rhelSpot+6:]
// return translated modular branch: // return translated modular branch:
return fmt.Sprintf("%s%d%s-%s_%s", pd.BranchPrefix, pd.Version, pd.BranchSuffix, moduleString, majorMinor) return fmt.Sprintf("%s%d%s-%s_%s", pd.BranchPrefix, pd.Version, pd.BranchSuffix, moduleString, majorMinor)
} }