Skip to content

Commit

Permalink
Prevalidate the --rpm-source args. (#67)
Browse files Browse the repository at this point in the history
Before starting the customization process, do some basic validation of
the `--rpm-source` args.
  • Loading branch information
cwize1 authored Jan 7, 2025
1 parent 5185692 commit cd12449
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions toolkit/tools/pkg/imagecustomizerlib/imagecustomizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ func createImageCustomizerParameters(buildDir string,
ic.useBaseImageRpmRepos = useBaseImageRpmRepos
ic.rpmsSources = rpmsSources

err = validateRpmSources(rpmsSources)
if err != nil {
return nil, err
}

ic.enableShrinkFilesystems = enableShrinkFilesystems
ic.outputSplitPartitionsFormat = outputSplitPartitionsFormat

Expand Down
16 changes: 12 additions & 4 deletions toolkit/tools/pkg/imagecustomizerlib/rpmsourcesmounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ func (m *rpmSourcesMounts) mountRpmSourcesHelper(buildDir string, imageChroot *s

case "repo":
err = m.createRepoFromRepoConfig(rpmSource, true, allReposConfig, imageChroot)

default:
return fmt.Errorf("unknown RPM source type (%s):\nmust be a .repo file or a directory", rpmSource)
}
if err != nil {
return err
Expand Down Expand Up @@ -274,6 +271,17 @@ func (m *rpmSourcesMounts) close() error {
return nil
}

func validateRpmSources(rpmsSources []string) error {
for _, rpmSource := range rpmsSources {
_, err := getRpmSourceFileType(rpmSource)
if err != nil {
return err
}
}

return nil
}

func getRpmSourceFileType(rpmSourcePath string) (string, error) {
// First, check if path points to a directory.
isDir, err := file.IsDir(rpmSourcePath)
Expand All @@ -297,7 +305,7 @@ func getRpmSourceFileType(rpmSourcePath string) (string, error) {
return "repo", nil

default:
return "", nil
return "", fmt.Errorf("unknown RPM source type (%s):\nmust be a .repo file or a directory", rpmSourcePath)
}
}

Expand Down

0 comments on commit cd12449

Please sign in to comment.