1
1
Fork 0
mirror of https://github.com/goreleaser/nfpm synced 2024-05-27 13:06:12 +02:00

fix(#103): ensure the package is not included in itself (#104)

* fix(#103): ensure the package is not included in itself when using globs to match files

* chore: switch strings.Contains to strings.HasSuffix
This commit is contained in:
Dj Gilcrease 2019-11-11 13:57:10 -08:00 committed by GitHub
parent f5f0a26477
commit 2eb4016806
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 0 deletions

View File

@ -32,6 +32,12 @@ A good way of making sure everything is all right is running the test suite:
$ make test
```
If on the ARM tests you are seeing `standard_init_linux.go:211: exec user process caused "exec format error"`:
```console
$sudo docker run --rm --privileged hypriot/qemu-register
```
## Test your change
You can create a branch for your changes and try to build from the source as you go:

View File

@ -194,6 +194,7 @@ func accept(t *testing.T, params acceptParms) {
f, err := os.Create(target)
require.NoError(t, err)
info.Target = target
require.NoError(t, pkg.Package(nfpm.WithDefaults(info), f))
//nolint:gosec
cmd := exec.Command(

View File

@ -83,6 +83,8 @@ func doPackage(path, target string) error {
if err != nil {
return err
}
info.Target = target
return pkg.Package(info, f)
}

View File

@ -131,6 +131,9 @@ func createFilesInsideTarGz(info *nfpm.Info, out *tar.Writer, created map[string
return md5buf, 0, err
}
for src, dst := range globbed {
if strings.HasSuffix(src, info.Target) {
continue
}
if err := createTree(out, dst, created); err != nil {
return md5buf, 0, err
}

View File

@ -119,6 +119,7 @@ type Info struct {
Homepage string `yaml:"homepage,omitempty"`
License string `yaml:"license,omitempty"`
Bindir string `yaml:"bindir,omitempty"`
Target string `yaml:"-"`
}
// Overridables contain the field which are overridable in a package

View File

@ -3,6 +3,7 @@
package rpm
import (
"fmt"
"io"
"io/ioutil"
"os"
@ -199,6 +200,10 @@ func createFilesInsideRPM(info *nfpm.Info, rpm *rpmpack.RPM) error {
return err
}
for src, dst := range globbed {
if strings.HasSuffix(src, info.Target) {
fmt.Println("skipping", src)
continue
}
err := copyToRPM(rpm, src, dst, config)
if err != nil {
return err