Skip to content

Commit

Permalink
fix: nfpm not including extra files
Browse files Browse the repository at this point in the history
closes #1980

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Dec 30, 2020
1 parent c613dd9 commit 1195844
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
14 changes: 12 additions & 2 deletions internal/pipe/nfpm/nfpm.go
Expand Up @@ -186,7 +186,9 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
}

var contents files.Contents
copy(overridden.Contents, contents)
for _, f := range overridden.Contents {
contents = append(contents, f)
}

// FPM meta package should not contain binaries at all
if !fpm.Meta {
Expand All @@ -202,7 +204,7 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
}
}

log.WithField("files", contents).Debug("all archive files")
log.WithField("files", destinations(contents)).Debug("all archive files")

var info = &nfpm.Info{
Arch: arch,
Expand Down Expand Up @@ -318,6 +320,14 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
return nil
}

func destinations(contents files.Contents) []string {
var result = make([]string, 0, len(contents))
for _, f := range contents {
result = append(result, f.Destination)
}
return result
}

func getPassphraseFromEnv(ctx *context.Context, packager string, nfpmID string) string {
var passphrase string

Expand Down
19 changes: 10 additions & 9 deletions internal/pipe/nfpm/nfpm_test.go
Expand Up @@ -158,9 +158,15 @@ func TestRunPipe(t *testing.T) {
require.NotEmpty(t, format)
require.Equal(t, pkg.Name, "mybin_1.0.0_Tux_"+pkg.Goarch+"-10-20."+format)
require.Equal(t, pkg.ExtraOr("ID", ""), "someid")
require.ElementsMatch(t, []string{
"/usr/share/testfile.txt",
"/etc/nope.conf",
"/etc/nope-rpm.conf",
"/etc/nope2.conf",
"/usr/bin/mybin",
}, destinations(pkg.ExtraOr("Files", files.Contents{}).(files.Contents)))
}
require.Len(t, ctx.Config.NFPMs[0].Contents, 4, "should not modify the config file list")

}

func TestInvalidNameTemplate(t *testing.T) {
Expand Down Expand Up @@ -725,17 +731,12 @@ func TestMeta(t *testing.T) {
require.NotEmpty(t, format)
require.Equal(t, pkg.Name, "mybin_1.0.0_Tux_"+pkg.Goarch+"-10-20."+format)
require.Equal(t, pkg.ExtraOr("ID", ""), "someid")
for _, f := range pkg.ExtraOr("Files", files.Contents{}).(files.Contents) {
require.NotEqual(t, "/usr/bin/mybin", f.Destination, "binary file should not have been added")
}
}

require.Len(t, ctx.Config.NFPMs[0].Contents, 3, "should not modify the config file list")

// ensure that no binaries added
for _, pkg := range packages {
contents := pkg.ExtraOr("Files", files.Contents{}).(files.Contents)
for _, f := range contents {
require.NotEqual(t, "/usr/bin/mybin", f.Destination, "binary file should not be added")
}
}
}

func TestSkipSign(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config.go
Expand Up @@ -339,8 +339,8 @@ type NFPMRPM struct {
Summary string `yaml:"summary,omitempty"`
Group string `yaml:"group,omitempty"`
Compression string `yaml:"compression,omitempty"`
ConfigNoReplaceFiles map[string]string `yaml:"config_noreplace_files,omitempty"` // depreacated: use contents instead
GhostFiles []string `yaml:"ghost_files,omitempty"` // depreacated: use contents instead
ConfigNoReplaceFiles map[string]string `yaml:"config_noreplace_files,omitempty"` // deprecated: use contents instead
GhostFiles []string `yaml:"ghost_files,omitempty"` // deprecated: use contents instead
Signature NFPMRPMSignature `yaml:"signature,omitempty"`
}

Expand Down

1 comment on commit 1195844

@vercel
Copy link

@vercel vercel bot commented on 1195844 Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.