Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mstg committed Nov 6, 2022
1 parent e859f54 commit 2a2b10b
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 75 deletions.
5 changes: 3 additions & 2 deletions cmd/srpmproc/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
package main

import (
"log"
"os"

"github.com/go-git/go-billy/v5/osfs"
"github.com/rocky-linux/srpmproc/pkg/srpmproc"
"github.com/spf13/cobra"
"log"
"os"
)

var fetch = &cobra.Command{
Expand Down
5 changes: 2 additions & 3 deletions cmd/srpmproc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ package main

import (
"encoding/json"
"github.com/rocky-linux/srpmproc/pkg/srpmproc"
"log"
"os"

"github.com/rocky-linux/srpmproc/pkg/srpmproc"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -97,7 +98,6 @@ func mn(_ *cobra.Command, _ []string) {
TaglessMode: taglessMode,
AltLookAside: altLookAside,
})

if err != nil {
log.Fatal(err)
}
Expand All @@ -111,7 +111,6 @@ func mn(_ *cobra.Command, _ []string) {
if err != nil {
log.Fatal(err)
}

}

func main() {
Expand Down
1 change: 1 addition & 0 deletions modulemd/modulemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package modulemd

import (
"fmt"

"github.com/go-git/go-billy/v5"
"gopkg.in/yaml.v3"
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/blob/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/blob/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
package gcs

import (
"cloud.google.com/go/storage"
"context"
"fmt"
"io/ioutil"

"cloud.google.com/go/storage"
)

type GCS struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/blob/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ 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"
"github.com/aws/aws-sdk-go/aws/session"
"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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/data/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/data/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions pkg/data/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/directives/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/directives/lookaside.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
1 change: 1 addition & 0 deletions pkg/directives/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pkg/directives/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/directives/spec_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/misc/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
// modular "stream-<NAME>-<VERSION>-rhel-<VERSION> branch pattern as well
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
if strings.HasPrefix(tag, fmt.Sprintf("refs/heads/%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)) {
return true
Expand Down
7 changes: 3 additions & 4 deletions pkg/modes/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ 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"
"sort"
"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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions pkg/rpmutils/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,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 = regexp.MustCompile("^(\\S+)-([\\w~%.+]+)-(\\w+(?:\\.[\\w+]+)+?)(?:\\.(\\w+))?(?:\\.rpm)?$")
)
9 changes: 5 additions & 4 deletions pkg/srpmproc/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/srpmproc/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ 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"
"path/filepath"
"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"
Expand Down
Loading

0 comments on commit 2a2b10b

Please sign in to comment.