From 2e1729ab2a6c568664ebb7178316f894c179b66f Mon Sep 17 00:00:00 2001 From: Atanas Dinov Date: Wed, 15 Nov 2023 11:47:34 +0200 Subject: [PATCH] Add RPMDir field to DirStructure Signed-off-by: Atanas Dinov --- pkg/build/dir_structure.go | 5 +++++ pkg/build/rpm.go | 12 +++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/build/dir_structure.go b/pkg/build/dir_structure.go index ea79dcbc..5d66d202 100644 --- a/pkg/build/dir_structure.go +++ b/pkg/build/dir_structure.go @@ -9,6 +9,8 @@ import ( const ( // scriptsSubDir contains user provided custom scripts. scriptsSubDir = "scripts" + // rpmsSubDir contains user provided RPM files. + rpmsSubDir = "rpms" ) type DirStructure struct { @@ -20,6 +22,8 @@ type DirStructure struct { CombustionDir string // ScriptsDir is an optional subdirectory under ImageConfigDir containing user provided custom scripts. ScriptsDir string + // RPMDir is an optional subdirectory under ImageConfigDir containing user provided RPM files. + RPMDir string // DeleteBuildDir indicates whether the BuildDir should be cleaned up after the image is built. DeleteBuildDir bool } @@ -43,6 +47,7 @@ func NewDirStructure(imageConfigDir, buildDir string, deleteBuildDir bool) (*Dir BuildDir: buildDir, CombustionDir: combustionDir, ScriptsDir: filepath.Join(imageConfigDir, scriptsSubDir), // may not exist + RPMDir: filepath.Join(imageConfigDir, rpmsSubDir), // may not exist DeleteBuildDir: deleteBuildDir, }, nil } diff --git a/pkg/build/rpm.go b/pkg/build/rpm.go index 57d73a72..be5e3f46 100644 --- a/pkg/build/rpm.go +++ b/pkg/build/rpm.go @@ -30,25 +30,23 @@ func (b *Builder) getRPMFileNames(rpmSourceDir string) ([]string, error) { } func (b *Builder) copyRPMs() error { - rpmSourceDir := filepath.Join(b.dirStructure.ImageConfigDir, "rpms") // Only proceed with copying the RPMs if the directory exists - _, err := os.Stat(rpmSourceDir) + _, err := os.Stat(b.dirStructure.RPMDir) if err != nil { if os.IsNotExist(err) { return nil } - return fmt.Errorf("checking for rpm directory at %s: %w", rpmSourceDir, err) + return fmt.Errorf("checking for rpm directory at %s: %w", b.dirStructure.RPMDir, err) } - rpmDestDir := b.dirStructure.CombustionDir - rpmFileNames, err := b.getRPMFileNames(rpmSourceDir) + rpmFileNames, err := b.getRPMFileNames(b.dirStructure.RPMDir) if err != nil { return fmt.Errorf("getting rpm file names: %w", err) } for _, rpm := range rpmFileNames { - sourcePath := filepath.Join(rpmSourceDir, rpm) - destPath := filepath.Join(rpmDestDir, rpm) + sourcePath := filepath.Join(b.dirStructure.RPMDir, rpm) + destPath := filepath.Join(b.dirStructure.CombustionDir, rpm) err = fileio.CopyFile(sourcePath, destPath) if err != nil {