Merge pull request #16 from dirkmueller/openela

Support the openELA "PATCHES" directory format as well
This commit is contained in:
Mustafa Gezen 2023-11-16 18:04:50 +01:00 committed by GitHub
commit f2864a875a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 9 deletions

View File

@ -23,7 +23,7 @@ package srpmproc
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
@ -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)
}
@ -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)
}
@ -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 {
@ -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)
}

View File

@ -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)
}
@ -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)
}