Repository: goreleaser/nfpm
Pull request #306 (2021-02-28 17:41:36)

feat: upgrade fileglob
upgrade to latest

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/goreleaser/nfpm/HBEdrvmBuJjBRvLe6ue5m2Byn6rB](https://vercel.com/goreleaser/nfpm/HBEdrvmBuJjBRvLe6ue5m2Byn6rB)  
✅ Preview: [https://nfpm-git-fileglob-goreleaser.vercel.app](https://nfpm-git-fileglob-goreleaser.vercel.app)


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/306?src=pr&el=h1) Report
> Merging [#306](https://codecov.io/gh/goreleaser/nfpm/pull/306?src=pr&el=desc) (a5464d4) into [master](https://codecov.io/gh/goreleaser/nfpm/commit/bf4f92763d7594ca06e71204262cda8ccd8028bb?el=desc) (bf4f927) will **increase** coverage by `0.02%`.
> The diff coverage is `100.00%`.

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

```diff
@@            Coverage Diff             @@
##           master     #306      +/-   ##
==========================================
+ Coverage   70.21%   70.24%   +0.02%     
==========================================
  Files           9        9              
  Lines        1108     1109       +1     
==========================================
+ Hits          778      779       +1     
  Misses        204      204              
  Partials      126      126              
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/306?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [files/files.go](https://codecov.io/gh/goreleaser/nfpm/pull/306/diff?src=pr&el=tree#diff-ZmlsZXMvZmlsZXMuZ28=) | `95.89% <100.00%> (+0.05%)` | :arrow_up: |
| [internal/glob/glob.go](https://codecov.io/gh/goreleaser/nfpm/pull/306/diff?src=pr&el=tree#diff-aW50ZXJuYWwvZ2xvYi9nbG9iLmdv) | `81.81% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/306?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/306?src=pr&el=footer). Last update [cf4fb12...53e68fd](https://codecov.io/gh/goreleaser/nfpm/pull/306?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/files/files.go b/files/files.go
index 28f9bc0..a0254c5 100644
--- a/files/files.go
+++ b/files/files.go
@@ -118,9 +118,6 @@ func (c *Content) Sys() interface{} {
 func ExpandContentGlobs(contents Contents, disableGlobbing bool) (files Contents, err error) {
 	for _, f := range contents {
 		var globbed map[string]string
-		if disableGlobbing {
-			f.Source = fileglob.QuoteMeta(f.Source)
-		}
 
 		switch f.Type {
 		case "ghost", "symlink":
@@ -133,7 +130,11 @@ func ExpandContentGlobs(contents Contents, disableGlobbing bool) (files Contents
 			continue
 		}
 
-		globbed, err = glob.Glob(f.Source, f.Destination)
+		var options []fileglob.OptFunc
+		if disableGlobbing {
+			options = append(options, fileglob.QuoteMeta)
+		}
+		globbed, err = glob.Glob(f.Source, f.Destination, options...)
 		if err != nil {
 			return nil, err
 		}
diff --git a/go.mod b/go.mod
index 07e7f9e..475ef67 100644
--- a/go.mod
+++ b/go.mod
@@ -12,7 +12,7 @@ require (
 	github.com/google/go-cmp v0.5.4 // indirect
 	github.com/google/rpmpack v0.0.0-20201225075926-0a97c2c4b688
 	github.com/goreleaser/chglog v0.1.2
-	github.com/goreleaser/fileglob v1.0.1
+	github.com/goreleaser/fileglob v1.2.0
 	github.com/imdario/mergo v0.3.11
 	github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect
 	github.com/sassoftware/go-rpmutils v0.0.0-20190420191620-a8f1baeba37b
diff --git a/go.sum b/go.sum
index 138317e..f1b4749 100644
--- a/go.sum
+++ b/go.sum
@@ -123,8 +123,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
 github.com/goreleaser/chglog v0.1.2 h1:tdzAb/ILeMnphzI9zQ7Nkq+T8R9qyXli8GydD8plFRY=
 github.com/goreleaser/chglog v0.1.2/go.mod h1:tTZsFuSZK4epDXfjMkxzcGbrIOXprf0JFp47BjIr3B8=
-github.com/goreleaser/fileglob v1.0.1 h1:FMmkd1M8NvBZomt1/iLhogfPhKFwgB5aJUOzke98wCw=
-github.com/goreleaser/fileglob v1.0.1/go.mod h1:rFyb2pXaK3YdnYnSjn6lifw0h2Q6s8OfOsx6I6bXkKE=
+github.com/goreleaser/fileglob v1.2.0 h1:OErqbdzeg/eibfDGPHDQDN8jL5u1jNyxA5IQzNPLLoU=
+github.com/goreleaser/fileglob v1.2.0/go.mod h1:rFyb2pXaK3YdnYnSjn6lifw0h2Q6s8OfOsx6I6bXkKE=
 github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
 github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
diff --git a/internal/glob/glob.go b/internal/glob/glob.go
index 179d0f5..142f18e 100644
--- a/internal/glob/glob.go
+++ b/internal/glob/glob.go
@@ -50,8 +50,8 @@ func (e ErrGlobNoMatch) Error() string {
 // Glob returns a map with source file path as keys and destination as values.
 // First the longest common prefix (lcp) of all globbed files is found. The destination
 // for each globbed file is then dst joined with src with the lcp trimmed off.
-func Glob(pattern, dst string) (map[string]string, error) {
-	matches, err := fileglob.Glob(pattern)
+func Glob(pattern, dst string, options ...fileglob.OptFunc) (map[string]string, error) {
+	matches, err := fileglob.Glob(pattern, append(options, fileglob.MaybeRootFS)...)
 	if errors.Is(err, os.ErrNotExist) {
 		return nil, err
 	}


Test patch:
diff --git a/apk/apk_test.go b/apk/apk_test.go
index 9a18ed2..46d8b65 100644
--- a/apk/apk_test.go
+++ b/apk/apk_test.go
@@ -11,6 +11,7 @@ import (
 	"fmt"
 	"io"
 	"io/ioutil"
+	"path/filepath"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
@@ -185,7 +186,9 @@ func TestNoInfo(t *testing.T) {
 }
 
 func TestFileDoesNotExist(t *testing.T) {
-	err := Default.Package(
+	abs, err := filepath.Abs("../testdata/whatever.confzzz")
+	require.NoError(t, err)
+	err = Default.Package(
 		nfpm.WithDefaults(&nfpm.Info{
 			Name:        "foo",
 			Arch:        "amd64",
@@ -215,7 +218,7 @@ func TestFileDoesNotExist(t *testing.T) {
 		}),
 		ioutil.Discard,
 	)
-	assert.EqualError(t, err, "matching \"../testdata/whatever.confzzz\": file does not exist")
+	assert.EqualError(t, err, fmt.Sprintf("matching \"%s\": file does not exist", filepath.ToSlash(abs)))
 }
 
 func TestNoFiles(t *testing.T) {
diff --git a/deb/deb_test.go b/deb/deb_test.go
index 78a57c4..f3f4240 100644
--- a/deb/deb_test.go
+++ b/deb/deb_test.go
@@ -259,7 +259,9 @@ func TestNoJoinsControl(t *testing.T) {
 }
 
 func TestDebFileDoesNotExist(t *testing.T) {
-	err := Default.Package(
+	abs, err := filepath.Abs("../testdata/whatever.confzzz")
+	require.NoError(t, err)
+	err = Default.Package(
 		nfpm.WithDefaults(&nfpm.Info{
 			Name:        "foo",
 			Arch:        "amd64",
@@ -289,7 +291,7 @@ func TestDebFileDoesNotExist(t *testing.T) {
 		}),
 		ioutil.Discard,
 	)
-	assert.EqualError(t, err, "matching \"../testdata/whatever.confzzz\": file does not exist")
+	assert.EqualError(t, err, fmt.Sprintf("matching \"%s\": file does not exist", filepath.ToSlash(abs)))
 }
 
 func TestDebNoFiles(t *testing.T) {
diff --git a/internal/glob/glob_test.go b/internal/glob/glob_test.go
index 5555e15..abfca68 100644
--- a/internal/glob/glob_test.go
+++ b/internal/glob/glob_test.go
@@ -1,6 +1,7 @@
 package glob
 
 import (
+	"path/filepath"
 	"testing"
 
 	"github.com/stretchr/testify/require"
@@ -46,6 +47,16 @@ func TestGlob(t *testing.T) {
 		require.Equal(t, "/foo/bar/dir_c/test_c.txt", files["testdata/dir_a/dir_c/test_c.txt"])
 	})
 
+	t.Run("to parent", func(t *testing.T) {
+		pattern := "../../testdata/fake"
+		abs, err := filepath.Abs(pattern)
+		require.NoError(t, err)
+		files, err := Glob(pattern, "/foo/fake")
+		require.NoError(t, err)
+		require.Len(t, files, 1)
+		require.Equal(t, "/foo/fake", files[filepath.ToSlash(abs)])
+	})
+
 	t.Run("single file", func(t *testing.T) {
 		files, err := Glob("testdata/dir_a/dir_b/*", "/foo/bar")
 		require.NoError(t, err)
@@ -62,7 +73,7 @@ func TestGlob(t *testing.T) {
 
 	t.Run("nil value", func(t *testing.T) {
 		files, err := Glob("does/not/exist", "/foo/bar")
-		require.EqualError(t, err, "matching \"does/not/exist\": file does not exist")
+		require.EqualError(t, err, "matching \"./does/not/exist\": file does not exist")
 		require.Nil(t, files)
 	})
 
diff --git a/rpm/rpm_test.go b/rpm/rpm_test.go
index 6a37028..a3d2cdb 100644
--- a/rpm/rpm_test.go
+++ b/rpm/rpm_test.go
@@ -381,8 +381,10 @@ func TestRPMFileDoesNotExist(t *testing.T) {
 			Type:        "config",
 		},
 	}
-	err := Default.Package(info, ioutil.Discard)
-	assert.EqualError(t, err, "matching \"../testdata/whatever.confzzz\": file does not exist")
+	abs, err := filepath.Abs("../testdata/whatever.confzzz")
+	require.NoError(t, err)
+	err = Default.Package(info, ioutil.Discard)
+	assert.EqualError(t, err, fmt.Sprintf("matching \"%s\": file does not exist", filepath.ToSlash(abs)))
 }
 
 func TestRPMMultiArch(t *testing.T) {