Repository: goreleaser/nfpm (go)

Issue:
Confusing behaviour with trailing `/` in destination
### What happened?

I have the following nfpm.yaml:

```yml
name: foo
version: 0.0.0
maintainer: asdf
arch: amd64
contents:
- dst: /usr/local/share/file/
  src: file.txt
```

Note the `/` at the end of the destination path. Because of that, I expect nfpm to install the file as `/usr/local/share/file/file.txt`. However, it installs the file as `/usr/local/share/file`. This is confusing because the trailing `/` indicates that the path is a directory, so the logical course of action would be to put the file into the directory.

### How can we reproduce this?

Copy the above nfpm.yaml, and create a file `file.txt`, and run `nfpm package -p deb`

### nfpm version

```bash
nfpm version nfpm version 2.22.0
commit: 5c3cc38943f1743bcaeb422c2dc65555fc9b12a1
built at: 2022-11-12T03:50:16Z
built by: goreleaser
module version: v2.22.0, checksum: h1:TC6tuxxFq0hL0WapI63+CkLMbcsYRbR7kAnLkRYAEbo=
```


### Search

- [X] I did search for other open and closed issues before opening this.

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

### Additional context

_No response_

Pull request description:
fix: relative paths to dirs
closes #575

Patch:
diff --git a/internal/glob/glob.go b/internal/glob/glob.go
index e225147..e6fca62 100644
--- a/internal/glob/glob.go
+++ b/internal/glob/glob.go
@@ -92,6 +92,11 @@ func Glob(pattern, dst string, ignoreMatchers bool) (map[string]string, error) {
 			continue
 		}
 
+		if strings.HasSuffix(dst, "/") {
+			files[src] = filepath.Join(dst, filepath.Base(src))
+			continue
+		}
+
 		relpath, err := filepath.Rel(prefix, src)
 		if err != nil {
 			// since prefix is a prefix of src a relative path should always be found


Test patch:
diff --git a/files/files_test.go b/files/files_test.go
index 2166267..06dceee 100644
--- a/files/files_test.go
+++ b/files/files_test.go
@@ -370,3 +370,15 @@ func TestGlobbingFilesWithDifferentSizesWithFileInfo(t *testing.T) {
 		t.Fatal("test FileInfos have the same size, expected different")
 	}
 }
+
+func TestDestEndsWithSlash(t *testing.T) {
+	result, err := files.ExpandContentGlobs(files.Contents{
+		{
+			Source:      "./testdata/globtest/a.txt",
+			Destination: "./foo/",
+		},
+	}, false)
+	require.NoError(t, err)
+	require.Len(t, result, 1)
+	require.Equal(t, "foo/a.txt", result[0].Destination)
+}
diff --git a/internal/glob/glob_test.go b/internal/glob/glob_test.go
index 721b3c8..d21daab 100644
--- a/internal/glob/glob_test.go
+++ b/internal/glob/glob_test.go
@@ -47,6 +47,13 @@ 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("dst is a dir", func(t *testing.T) {
+		files, err := Glob("./testdata/dir_a/dir_b/test_b.txt", "/foo/bar/", false)
+		require.NoError(t, err)
+		require.Len(t, files, 1)
+		require.Equal(t, "/foo/bar/test_b.txt", files["testdata/dir_a/dir_b/test_b.txt"])
+	})
+
 	t.Run("to parent", func(t *testing.T) {
 		pattern := "../../testdata/fake"
 		abs, err := filepath.Abs(pattern)