Skip to content

Commit

Permalink
Merge pull request #16 from dirkmueller/openela
Browse files Browse the repository at this point in the history
Support the openELA "PATCHES" directory format as well
  • Loading branch information
mstg authored Nov 16, 2023
2 parents 963b5d2 + 82271f5 commit f2864a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
25 changes: 18 additions & 7 deletions pkg/srpmproc/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package srpmproc
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand All @@ -48,10 +48,16 @@ import (

func cfgPatches(pd *data.ProcessData, md *data.ModeData, patchTree *git.Worktree, pushTree *git.Worktree) error {
// check CFG patches
_, err := patchTree.Filesystem.Stat("ROCKY/CFG")
// use PATCHES directory if it exists otherwise ROCKY/CFG
cfgdir := "PATCHES"
_, err := patchTree.Filesystem.Stat(cfgdir)
if err != nil {
cfgdir = "ROCKY/CFG"
}
_, err = patchTree.Filesystem.Stat(cfgdir)
if err == nil {
// iterate through patches
infos, err := patchTree.Filesystem.ReadDir("ROCKY/CFG")
infos, err := patchTree.Filesystem.ReadDir(cfgdir)
if err != nil {
return fmt.Errorf("could not walk patches: %v", err)
}
Expand All @@ -63,12 +69,12 @@ func cfgPatches(pd *data.ProcessData, md *data.ModeData, patchTree *git.Worktree
}

pd.Log.Printf("applying directive %s", info.Name())
filePath := filepath.Join("ROCKY/CFG", info.Name())
filePath := filepath.Join(cfgdir, info.Name())
directive, err := patchTree.Filesystem.Open(filePath)
if err != nil {
return fmt.Errorf("could not open directive file %s: %v", info.Name(), err)
}
directiveBytes, err := ioutil.ReadAll(directive)
directiveBytes, err := io.ReadAll(directive)
if err != nil {
return fmt.Errorf("could not read directive file: %v", err)
}
Expand Down Expand Up @@ -96,7 +102,12 @@ func cfgPatches(pd *data.ProcessData, md *data.ModeData, patchTree *git.Worktree

func applyPatches(pd *data.ProcessData, md *data.ModeData, patchTree *git.Worktree, pushTree *git.Worktree) error {
// check if patches exist
_, err := patchTree.Filesystem.Stat("ROCKY")
cfgdir := "PATCHES"
_, err := patchTree.Filesystem.Stat(cfgdir)
if err != nil {
cfgdir = "ROCKY"
}
_, err = patchTree.Filesystem.Stat(cfgdir)
if err == nil {
err := cfgPatches(pd, md, patchTree, pushTree)
if err != nil {
Expand Down Expand Up @@ -315,7 +326,7 @@ func patchModuleYaml(pd *data.ProcessData, md *data.ModeData) error {
}
}

content, err := ioutil.ReadAll(f)
content, err := io.ReadAll(f)
if err != nil {
return fmt.Errorf("could not read modulemd file: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/srpmproc/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ func ProcessRPM(pd *data.ProcessData) (*srpmprocpb.ProcessResponse, error) {
if err != nil {
return nil, fmt.Errorf("could not open ignored source file %s: %v", sourcePath, err)
}
sourceFileBts, err := ioutil.ReadAll(sourceFile)
sourceFileBts, err := io.ReadAll(sourceFile)
if err != nil {
return nil, fmt.Errorf("could not read the whole of ignored source file: %v", err)
}
Expand Down Expand Up @@ -1299,7 +1299,7 @@ func processLookasideSources(pd *data.ProcessData, md *data.ModeData, localDir s
if err != nil {
return fmt.Errorf("could not open ignored source file %s: %v", sourcePath, err)
}
sourceFileBts, err := ioutil.ReadAll(sourceFile)
sourceFileBts, err := io.ReadAll(sourceFile)
if err != nil {
return fmt.Errorf("could not read the whole of ignored source file: %v", err)
}
Expand Down

0 comments on commit f2864a8

Please sign in to comment.