Add support for importing modular components (RPMs)

This commit is contained in:
Mustafa Gezen 2023-09-07 23:43:29 +02:00
parent d7b81bacea
commit 91fc789dcb
Signed by: mustafa
GPG Key ID: DCDF010D946438C1
3 changed files with 52 additions and 0 deletions

View File

@ -345,6 +345,33 @@ func (s *State) expandLayout(targetFS billy.Filesystem) error {
return nil
}
// getStreamSuffix adds a "-stream-X" suffix if the given RPM is a module component.
// This is determined using Modularitylabel (5096). If the label is present, then
// the RPM is a module component. Label format is MODULE_NAME:STREAM:VERSION:CONTEXT.
// This function returns an empty string if the RPM is not a module component.
func (s *State) getStreamSuffix() (string, error) {
// Check the modularity label
label, err := s.rpm.Header.GetString(5096)
if err != nil {
// If it's not present at all, it will fail with "No such entry 5096"
return "", nil
}
// If the label is empty, then the RPM is not a module component
if label == "" {
return "", nil
}
// Split the label
parts := strings.Split(label, ":")
if len(parts) != 4 {
return "", fmt.Errorf("invalid modularity label")
}
// Return the stream
return fmt.Sprintf("-stream-%s", parts[1]), nil
}
// getRepo returns the target repository for the SRPM.
// This is where the payload is uploaded to.
func (s *State) getRepo(opts *git.CloneOptions, storer storage2.Storer, targetFS billy.Filesystem, osRelease string) (*git.Repository, string, error) {
@ -387,6 +414,13 @@ func (s *State) getRepo(opts *git.CloneOptions, storer storage2.Storer, targetFS
}
}
// Check if module component
streamSuffix, err := s.getStreamSuffix()
if err != nil {
return nil, "", errors.Wrap(err, "failed to get stream suffix")
}
branch += streamSuffix
// Set branch to dist tag
opts.ReferenceName = plumbing.NewBranchReferenceName(branch)
opts.SingleBranch = true

View File

@ -264,6 +264,24 @@ func TestWriteMetadataExpandLayout(t *testing.T) {
require.Equal(t, "f002f60baed7a47ca3e98b8dd7ece2f7352dac9ffab7ae3557eb56b481ce2f86 SOURCES/efi-rpm-macros-3.tar.bz2\n", string(buf))
}
func TestGetStreamSuffix(t *testing.T) {
s, err := FromFile("testdata/nginx-1.14.1-9.module+el8.4.0+542+81547229.src.rpm", false)
require.Nil(t, err)
suffix, err := s.getStreamSuffix()
require.Nil(t, err)
require.Equal(t, "-stream-1.14", suffix)
}
func TestGetStreamSuffix_NotModuleComponent(t *testing.T) {
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
require.Nil(t, err)
suffix, err := s.getStreamSuffix()
require.Nil(t, err)
require.Equal(t, "", suffix)
}
func TestGetRepo_New(t *testing.T) {
s, err := FromFile("testdata/efi-rpm-macros-3-3.el8.src.rpm", false)
require.Nil(t, err)