Repository: goreleaser/nfpm
Pull request #209 (2020-08-17 15:37:34)

fix: Remove leading slashes from files in .tag.gz files in deb.
In earlier pull requests, I accidentally added symlink and changelog files to the `deb` `.tar.gz` files with a leading `/`. This pull requests removes these leading `/`s such that no warning is displayed by `tar` anymore when unpacking. I also added a tests that assures that no files included in the data and control `.tar.gz` starts with `/`.

vercel[bot]: 
The deployment has failed to due an unexpected error within Vercel (your source code is not at fault).

Our team has been notified and will resolve the issue shortly.
	
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: *In Progress*  
✅ Preview: *In Progress*



Patch:
diff --git a/deb/deb.go b/deb/deb.go
index bdfda53..77661da 100644
--- a/deb/deb.go
+++ b/deb/deb.go
@@ -154,7 +154,7 @@ func createSymlinksInsideTarGz(info *nfpm.Info, out *tar.Writer, created map[str
 		}
 
 		err := newItemInsideTarGz(out, []byte{}, &tar.Header{
-			Name:     src,
+			Name:     strings.TrimLeft(src, "/"),
 			Linkname: dst,
 			Typeflag: tar.TypeSymlink,
 			ModTime:  time.Now(),
@@ -392,7 +392,7 @@ func newItemInsideTarGz(out *tar.Writer, content []byte, header *tar.Header) err
 
 func newFileInsideTarGz(out *tar.Writer, name string, content []byte) error {
 	return newItemInsideTarGz(out, content, &tar.Header{
-		Name:     filepath.ToSlash(name),
+		Name:     strings.TrimLeft(filepath.ToSlash(name), "/"),
 		Size:     int64(len(content)),
 		Mode:     0644,
 		ModTime:  time.Now(),


Test patch:
diff --git a/deb/deb_test.go b/deb/deb_test.go
index f1177c2..fa6d40a 100644
--- a/deb/deb_test.go
+++ b/deb/deb_test.go
@@ -619,11 +619,43 @@ func TestSymlink(t *testing.T) {
 	packagedSymlinkHeader, err := extractFileHeaderFromTarGz(dataTarGz, symlink)
 	require.NoError(t, err)
 
-	assert.Equal(t, symlink, packagedSymlinkHeader.Name)
+	assert.Equal(t, symlink, path.Join("/", packagedSymlinkHeader.Name))
 	assert.Equal(t, uint8(tar.TypeSymlink), packagedSymlinkHeader.Typeflag)
 	assert.Equal(t, symlinkTarget, packagedSymlinkHeader.Linkname)
 }
 
+func TestNoLeadingSlashInTarGzFiles(t *testing.T) {
+	info := exampleInfo()
+	info.Symlinks = map[string]string{
+		"/symlink/to/fake.txt": "/usr/share/doc/fake/fake.txt",
+	}
+	info.Changelog = "../testdata/changelog.yaml"
+
+	dataTarGz, md5sums, instSize, err := createDataTarGz(info)
+	require.NoError(t, err)
+	testNoLeadingSlashInTarGzFiles(t, dataTarGz)
+
+	controlTarGz, err := createControl(instSize, md5sums, info)
+	require.NoError(t, err)
+	testNoLeadingSlashInTarGzFiles(t, controlTarGz)
+}
+
+func testNoLeadingSlashInTarGzFiles(t *testing.T, tarGzFile []byte) {
+	tarFile, err := gzipInflate(tarGzFile)
+	require.NoError(t, err)
+
+	tr := tar.NewReader(bytes.NewReader(tarFile))
+	for {
+		hdr, err := tr.Next()
+		if err == io.EOF {
+			break // End of archive
+		}
+		require.NoError(t, err)
+
+		assert.False(t, strings.HasPrefix(hdr.Name, "/"), "%s starts with /", hdr.Name)
+	}
+}
+
 func extractFileFromTarGz(tarGzFile []byte, filename string) ([]byte, error) {
 	tarFile, err := gzipInflate(tarGzFile)
 	if err != nil {