diff --git a/rpm.go b/rpm.go index 6600e9d..f65b7ca 100644 --- a/rpm.go +++ b/rpm.go @@ -73,6 +73,9 @@ type RPMMetaData struct { // Prefixes is used for relocatable packages, usually with a one item // slice, e.g. `["/opt"]`. Prefixes []string + // SourceRPM indicates this is a source RPM (as opposed to a binary RPM). + // When true, the SOURCERPM tag is omitted from the header. + SourceRPM bool Provides, Obsoletes, Suggests, @@ -425,7 +428,9 @@ func (r *RPM) writeGenIndexes(h *index) { // rpm utilities look for the sourcerpm tag to deduce if this is not a source rpm (if it has a sourcerpm, // it is NOT a source rpm). - h.Add(tagSourceRPM, EntryString(fmt.Sprintf("%s-%s.src.rpm", r.Name, r.FullVersion()))) + if !r.SourceRPM { + h.Add(tagSourceRPM, EntryString(fmt.Sprintf("%s-%s.src.rpm", r.Name, r.FullVersion()))) + } if r.pretrans != "" { h.Add(tagPretrans, EntryString(r.pretrans)) h.Add(tagPretransProg, EntryString("/bin/sh")) diff --git a/rpm_test.go b/rpm_test.go index 79edf4c..825583d 100644 --- a/rpm_test.go +++ b/rpm_test.go @@ -182,6 +182,51 @@ func TestAllowListDirs(t *testing.T) { } } +func TestSourceRPMNoSourceRPMTag(t *testing.T) { + r, err := NewRPM(RPMMetaData{ + Name: "test", + Version: "1.0", + Release: "1", + Summary: "test summary", + Licence: "MIT", + SourceRPM: true, + }) + if err != nil { + t.Fatalf("NewRPM returned error %v", err) + } + + var b bytes.Buffer + if err := r.Write(&b); err != nil { + t.Fatalf("Write returned error %v", err) + } + + data := b.Bytes() + sourceRPMValue := "test-1.0-1.src.rpm" + if bytes.Contains(data, []byte(sourceRPMValue)) { + t.Errorf("source RPM should not contain SOURCERPM tag value %q, but found it", sourceRPMValue) + } + + r2, err := NewRPM(RPMMetaData{ + Name: "test", + Version: "1.0", + Release: "1", + Summary: "test summary", + Licence: "MIT", + }) + if err != nil { + t.Fatalf("NewRPM returned error %v", err) + } + + b.Reset() + if err := r2.Write(&b); err != nil { + t.Fatalf("Write returned error %v", err) + } + + if !bytes.Contains(b.Bytes(), []byte(sourceRPMValue)) { + t.Errorf("binary RPM should contain SOURCERPM tag value %q, but did not find it", sourceRPMValue) + } +} + func TestMinimalSpec(t *testing.T) { r, err := NewRPM(RPMMetaData{ Name: "test",