Skip to content

Commit

Permalink
Add RPMDir field to DirStructure
Browse files Browse the repository at this point in the history
Signed-off-by: Atanas Dinov <[email protected]>
  • Loading branch information
atanasdinov committed Nov 15, 2023
1 parent f7b78f9 commit 2e1729a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions pkg/build/dir_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
12 changes: 5 additions & 7 deletions pkg/build/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2e1729a

Please sign in to comment.