Support inconsistent metadata naming and case-insensitive tags

This commit is contained in:
Mustafa Gezen 2022-05-09 19:57:43 +02:00
parent 8199a79889
commit 16ad80fdeb
5 changed files with 50 additions and 16 deletions

View File

@ -21,6 +21,7 @@
package main
import (
"github.com/go-git/go-billy/v5/osfs"
"github.com/rocky-linux/srpmproc/pkg/srpmproc"
"github.com/spf13/cobra"
"log"
@ -47,7 +48,7 @@ func runFetch(_ *cobra.Command, _ []string) {
log.Fatalf("could not get working directory: %v", err)
}
err = srpmproc.Fetch(os.Stdout, cdnUrl, wd, nil)
err = srpmproc.Fetch(os.Stdout, cdnUrl, wd, osfs.New("/"), nil)
if err != nil {
log.Fatal(err)
}

View File

@ -27,7 +27,7 @@ func GetTagImportRegex(pd *data.ProcessData) *regexp.Regexp {
initialVerRegex += ".+"
}
regex := fmt.Sprintf("refs/tags/(imports/(%s)/(%s))", branchRegex, initialVerRegex)
regex := fmt.Sprintf("(?i)refs/tags/(imports/(%s)/(%s))", branchRegex, initialVerRegex)
return regexp.MustCompile(regex)
}

View File

@ -235,7 +235,24 @@ func (g *GitMode) WriteSource(pd *data.ProcessData, md *data.ModeData) error {
return fmt.Errorf("could not add Worktree: %v", err)
}
metadataFile, err := md.Worktree.Filesystem.Open(fmt.Sprintf(".%s.metadata", md.Name))
metadataPath := ""
ls, err := md.Worktree.Filesystem.ReadDir(".")
if err != nil {
return fmt.Errorf("could not read directory: %v", err)
}
for _, f := range ls {
if strings.HasSuffix(f.Name(), ".metadata") {
if metadataPath != "" {
return fmt.Errorf("multiple metadata files found")
}
metadataPath = f.Name()
}
}
if metadataPath == "" {
metadataPath = fmt.Sprintf(".%s.metadata", md.Name)
}
metadataFile, err := md.Worktree.Filesystem.Open(metadataPath)
if err != nil {
pd.Log.Printf("warn: could not open metadata file, so skipping: %v", err)
return nil

View File

@ -3,6 +3,7 @@ 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"
@ -14,26 +15,26 @@ import (
"strings"
)
func Fetch(logger io.Writer, cdnUrl string, dir string, storage blob.Storage) error {
func Fetch(logger io.Writer, cdnUrl string, dir string, fs billy.Filesystem, storage blob.Storage) error {
pd := &data.ProcessData{
Log: log.New(logger, "", log.LstdFlags),
}
metadataPath := ""
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if strings.HasSuffix(path, ".metadata") {
if metadataPath != "" {
return errors.New("multiple metadata files")
}
metadataPath = path
}
return nil
})
ls, err := fs.ReadDir(dir)
if err != nil {
return err
}
for _, f := range ls {
if strings.HasSuffix(f.Name(), ".metadata") {
if metadataPath != "" {
return errors.New("multiple metadata files found")
}
metadataPath = filepath.Join(dir, f.Name())
}
}
metadataFile, err := os.Open(metadataPath)
metadataFile, err := fs.Open(metadataPath)
if err != nil {
return fmt.Errorf("could not open metadata file: %v", err)
}
@ -103,7 +104,7 @@ func Fetch(logger io.Writer, cdnUrl string, dir string, storage blob.Storage) er
return fmt.Errorf("could create all directories")
}
f, err := os.Create(filepath.Join(dir, path))
f, err := fs.Create(filepath.Join(dir, path))
if err != nil {
return fmt.Errorf("could not open file pointer: %v", err)
}

View File

@ -472,7 +472,22 @@ func ProcessRPM(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error) {
}
// get ignored files hash and add to .{Name}.metadata
metadataFile := fmt.Sprintf(".%s.metadata", md.Name)
metadataFile := ""
ls, err := md.Worktree.Filesystem.ReadDir(".")
if err != nil {
return nil, fmt.Errorf("could not read directory: %v", err)
}
for _, f := range ls {
if strings.HasSuffix(f.Name(), ".metadata") {
if metadataFile != "" {
return nil, fmt.Errorf("multiple metadata files found")
}
metadataFile = f.Name()
}
}
if metadataFile == "" {
metadataFile = fmt.Sprintf(".%s.metadata", md.Name)
}
metadata, err := w.Filesystem.Create(metadataFile)
if err != nil {
return nil, fmt.Errorf("could not create metadata file: %v", err)