Repository: goreleaser/nfpm
Pull request #114 (2019-12-30 12:03:35)

fix: make epoch work again
Epoch is already merged in google/rpmpack (https://github.com/google/rpmpack/commit/aa36bfddb3a0c725e19c73e75d76fea48882c399)

marcsauter: linter fails on things I didn't touch?
caarlos0: new linter version it seems, its broken on master too, I'll fix there...

meanwhile, can you add some tests?

thanks :) 
caarlos0: fixed on master
codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/114?src=pr&el=h1) Report
> Merging [#114](https://codecov.io/gh/goreleaser/nfpm/pull/114?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/nfpm/commit/100ecf83a4e5409d9715674dc0d4d8c7ad91f4fb?src=pr&el=desc) will **decrease** coverage by `0.16%`.
> The diff coverage is `60%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/nfpm/pull/114/graphs/tree.svg?width=650&token=9QKGIxn7wg&height=150&src=pr)](https://codecov.io/gh/goreleaser/nfpm/pull/114?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master    #114      +/-   ##
=========================================
- Coverage   70.46%   70.3%   -0.17%     
=========================================
  Files           5       5              
  Lines         491     495       +4     
=========================================
+ Hits          346     348       +2     
- Misses         91      92       +1     
- Partials       54      55       +1
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/114?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [rpm/rpm.go](https://codecov.io/gh/goreleaser/nfpm/pull/114/diff?src=pr&el=tree#diff-cnBtL3JwbS5nbw==) | `70.62% <60%> (-0.53%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/114?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/114?src=pr&el=footer). Last update [100ecf8...afa761d](https://codecov.io/gh/goreleaser/nfpm/pull/114?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

caarlos0: thanks!

Patch:
diff --git a/go.mod b/go.mod
index b511f56..5534deb 100644
--- a/go.mod
+++ b/go.mod
@@ -9,7 +9,7 @@ require (
 	github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
 	github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb
 	github.com/davecgh/go-spew v1.1.1 // indirect
-	github.com/google/rpmpack v0.0.0-20191123225850-3293c964e1e6
+	github.com/google/rpmpack v0.0.0-20191226140753-aa36bfddb3a0
 	github.com/imdario/mergo v0.3.8
 	github.com/kr/pretty v0.1.0 // indirect
 	github.com/mattn/go-zglob v0.0.1
diff --git a/go.sum b/go.sum
index 18041af..c91e2e3 100644
--- a/go.sum
+++ b/go.sum
@@ -16,8 +16,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
 github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
-github.com/google/rpmpack v0.0.0-20191123225850-3293c964e1e6 h1:iTi+hixsnUSMvXFp3vr+84Paw9+jyDikfmMcZlTMoTI=
-github.com/google/rpmpack v0.0.0-20191123225850-3293c964e1e6/go.mod h1:RaTPr0KUf2K7fnZYLNDrr8rxAamWs3iNywJLtQ2AzBg=
+github.com/google/rpmpack v0.0.0-20191226140753-aa36bfddb3a0 h1:BW6OvS3kpT5UEPbCZ+KyX/OB4Ks9/MNMhWjqPPkZxsE=
+github.com/google/rpmpack v0.0.0-20191226140753-aa36bfddb3a0/go.mod h1:RaTPr0KUf2K7fnZYLNDrr8rxAamWs3iNywJLtQ2AzBg=
 github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
 github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
 github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
diff --git a/rpm/rpm.go b/rpm/rpm.go
index 5f1b51f..187d95c 100644
--- a/rpm/rpm.go
+++ b/rpm/rpm.go
@@ -7,6 +7,7 @@ import (
 	"io"
 	"io/ioutil"
 	"os"
+	"strconv"
 	"strings"
 	"time"
 
@@ -81,13 +82,17 @@ func (*RPM) Package(info *nfpm.Info, w io.Writer) error {
 
 func buildRPMMeta(info *nfpm.Info) (*rpmpack.RPMMetaData, error) {
 	var (
-		err error
+		err   error
+		epoch uint64
 		provides,
 		depends,
 		replaces,
 		suggests,
 		conflicts rpmpack.Relations
 	)
+	if epoch, err = strconv.ParseUint(defaultTo(info.Epoch, "0"), 10, 32); err != nil {
+		return nil, err
+	}
 	if provides, err = toRelation(info.Provides); err != nil {
 		return nil, err
 	}
@@ -115,6 +120,7 @@ func buildRPMMeta(info *nfpm.Info) (*rpmpack.RPMMetaData, error) {
 		Description: info.Description,
 		Version:     info.Version,
 		Release:     defaultTo(info.Release, "1"),
+		Epoch:       uint32(epoch),
 		Arch:        info.Arch,
 		OS:          info.Platform,
 		Licence:     info.License,


Test patch:
diff --git a/rpm/rpm_test.go b/rpm/rpm_test.go
index fb07744..7846d80 100644
--- a/rpm/rpm_test.go
+++ b/rpm/rpm_test.go
@@ -15,6 +15,7 @@ import (
 const (
 	tagVersion     = 0x03e9 // 1001
 	tagRelease     = 0x03ea // 1002
+	tagEpoch       = 0x03eb // 1003
 	tagSummary     = 0x03ec // 1004
 	tagDescription = 0x03ed // 1005
 	tagGroup       = 0x03f8 // 1016
@@ -99,6 +100,13 @@ func TestRPM(t *testing.T) {
 	assert.NoError(t, err)
 	assert.Equal(t, "1", release)
 
+	epoch, err := rpm.Header.Get(tagEpoch)
+	assert.NoError(t, err)
+	epochUint32, ok := epoch.([]uint32)
+	assert.Len(t, epochUint32, 1)
+	assert.True(t, ok)
+	assert.Equal(t, uint32(0), epochUint32[0])
+
 	group, err := rpm.Header.GetString(tagGroup)
 	assert.NoError(t, err)
 	assert.Equal(t, "Development/Tools", group)
@@ -122,6 +130,7 @@ func TestWithRPMTags(t *testing.T) {
 
 	var info = exampleInfo()
 	info.Release = "3"
+	info.Epoch = "42"
 	info.RPM = nfpm.RPM{
 		Group: "default",
 	}
@@ -142,6 +151,13 @@ func TestWithRPMTags(t *testing.T) {
 	assert.NoError(t, err)
 	assert.Equal(t, "3", release)
 
+	epoch, err := rpm.Header.Get(tagEpoch)
+	assert.NoError(t, err)
+	epochUint32, ok := epoch.([]uint32)
+	assert.Len(t, epochUint32, 1)
+	assert.True(t, ok)
+	assert.Equal(t, uint32(42), epochUint32[0])
+
 	group, err := rpm.Header.GetString(tagGroup)
 	assert.NoError(t, err)
 	assert.Equal(t, "default", group)
@@ -155,6 +171,24 @@ func TestWithRPMTags(t *testing.T) {
 	assert.Equal(t, info.Description, description)
 }
 
+func TestWithInvalidEpoch(t *testing.T) {
+	f, err := ioutil.TempFile("", "test.rpm")
+	defer func() {
+		_ = f.Close()
+		err = os.Remove(f.Name())
+		assert.NoError(t, err)
+	}()
+
+	var info = exampleInfo()
+	info.Release = "3"
+	info.Epoch = "-1"
+	info.RPM = nfpm.RPM{
+		Group: "default",
+	}
+	info.Description = "first line\nsecond line\nthird line"
+	assert.Error(t, Default.Package(info, f))
+}
+
 func TestRPMScripts(t *testing.T) {
 	info := exampleInfo()
 	f, err := ioutil.TempFile(".", fmt.Sprintf("%s-%s-*.rpm", info.Name, info.Version))