Repository: goreleaser/nfpm (go)

Issue:
nfpm: error: cannot write header of opt/cni/bin/bridge to data.tar.gz: archive/tar: missed writing 90016 bytes
```
nfpm -v
2.3.1
```

I get the following error when trying to build a deb. Building rpm is fine. What makes this strange is my original nfpm file works. I've add it below as well.
```
nfpm pkg --packager deb --target ./dist/ --config nfpm.yaml
using deb packager...
nfpm: error: cannot write header of opt/cni/bin/bridge to data.tar.gz: archive/tar: missed writing 90016 bytes
```

nfpm.yaml that causes error:
```
version: "v2.2.1"
release: 1

name: "podman2-xcast"
arch: "amd64"
platform: "linux"
section: "default"
priority: "extra"
description: |
  ONLY v2.x.x of podman. Podman is a container runtime. This package also holds it's required utils.
    podman, podman-remote, conmon, crun, runc, fuse-overlayfs, slirp4netns, cni-plugins.
    Also default configs. /etc/cni/net.d, /etc/containers.

conflicts:
  - podman
  - slirp4netns
  - containernetworking-plugins
  - fuse-overlayfs
  - containers-common

empty_folders:
  - /var/lib/cni
  - /var/lib/containers
  - /var/lib/containers/sigstore

contents:
  - src: ./usr/**/*
    dst: /usr
    file_info:
      owner: root
      group: root
  - src: ./opt/podman/bin
    dst: /opt/podman/bin
    file_info:
      mode: 0755
      owner: root
      group: root
  - src: ./opt/cni/bin
    dst: /opt/cni/bin
    file_info:
      mode: 0755
      owner: root
      group: root

  - src: /opt/podman/bin/podman-remote
    dst: /usr/bin/podman-remote
    type: symlink
  - src: /opt/podman/bin/slirp4netns
    dst: /usr/bin/slirp4netns
    type: symlink
  - src: /opt/podman/bin/fuse-overlayfs
    dst: /usr/bin/fuse-overlayfs
    type: symlink

  - src: ./etc/cni/net.d/87-podman-bridge.conflist
    dst: /etc/cni/net.d/87-podman-bridge.conflist
    type: config|noreplace
    file_info:
      owner: root
      group: root
  - src: ./etc/containers/**/*
    dst: /etc/containers
    type: config|noreplace
    file_info:
      owner: root
      group: root
```
Contents of ./opt/cni
```
opt/cni/:
total 4
drwxr-xr-x 2 dude root 4096 Sep 18  2020 bin

opt/cni/bin:
total 51348
-rwxr-xr-x 1 dude root 2602576 Aug 26  2020 bandwidth
-rwxr-xr-x 1 dude root 2869904 Aug 26  2020 bridge
-rwxr-xr-x 1 dude root 4197419 Sep 18  2020 container-iptables
-rwxr-xr-x 1 dude root 7314160 Aug 26  2020 dhcp
-rwxr-xr-x 1 dude root 3600208 Aug 26  2020 firewall
-rwxr-xr-x 1 dude root 2085680 Aug 26  2020 flannel
-rwxr-xr-x 1 dude root 2602448 Aug 26  2020 host-device
-rwxr-xr-x 1 dude root 2225008 Aug 26  2020 host-local
-rwxr-xr-x 1 dude root 3036768 Sep 14  2018 host-local-v0.7.0
-rwxr-xr-x 1 dude root 2692592 Aug 26  2020 ipvlan
-rwxr-xr-x 1 dude root 2150896 Aug 26  2020 loopback
-rwxr-xr-x 1 dude root 2745904 Aug 26  2020 macvlan
-rwxr-xr-x 1 dude root 2435184 Aug 26  2020 portmap
-rwxr-xr-x 1 dude root 2824816 Aug 26  2020 ptp
-rwxr-xr-x 1 dude root 2269776 Aug 26  2020 sbr
-rwxr-xr-x 1 dude root 1958128 Aug 26  2020 static
-rwxr-xr-x 1 dude root 2232816 Aug 26  2020 tuning
-rwxr-xr-x 1 dude root 2692592 Aug 26  2020 vlan
```

nfpm.yaml file that successfully builds deb:
```
version: "v2.2.1"
release: 1

name: "podman2-xcast"
arch: "amd64"
platform: "linux"
section: "default"
priority: "extra"
description: |
  ONLY v2.x.x of podman. Podman is a container runtime. This package also holds it's required utils.
    podman, podman-remote, conmon, crun, runc, fuse-overlayfs, slirp4netns, cni-plugins.
    Also default configs. /etc/cni/net.d, /etc/containers.
    ADD /opt/podman/bin AND /opt/cni/bin TO SYSTEM PATH.

conflicts:
  - podman
  - slirp4netns
  - containernetworking-plugins
  - fuse-overlayfs
  - containers-common

contents:
  - src: ./opt/podman
    dst: /opt/podman
  - src: /opt/podman/bin/podman
    dst: /usr/bin/podman
    type: symlink
  - src: /opt/podman/bin/podman-remote
    dst: /usr/bin/podman-remote
    type: symlink
  - src: /opt/podman/bin/slirp4netns
    dst: /usr/bin/slirp4netns
    type: symlink
  - src: /opt/podman/bin/fuse-overlayfs
    dst: /usr/bin/fuse-overlayfs
    type: symlink

  - src: ./usr/
    dst: /usr/

  - src: ./opt/cni
    dst: /opt/cni
  - src: ./etc/cni
    dst: /etc/cni
    type: config
  - src: ./etc/containers
    dst: /etc/containers
    type: config

empty_folders:
  - /var/lib/cni
  - /var/lib/containers
  - /var/lib/containers/sigstore
```

Pull request:
fix: Ensure globbed FileInfo always has correct size
When globbing a file that has a FileInfo set, we would reuse the pointer
to the original file's FileInfo even if the matched files' sizes are
different, causing deb to error when writing the data file due to
mismatching sizes.

Copy the FileInfo and recalculate its size when globbing. Add a test
case to check this scenario.

Fixes #316.

Patch:
diff --git a/files/files.go b/files/files.go
index 9fcf422..1d85755 100644
--- a/files/files.go
+++ b/files/files.go
@@ -177,11 +177,18 @@ func ExpandContentGlobs(contents Contents, disableGlobbing bool) (files Contents
 
 func appendGlobbedFiles(all Contents, globbed map[string]string, origFile *Content) (Contents, error) {
 	for src, dst := range globbed {
+		// if the file has a FileInfo, we need to copy it but recalculate its size
+		newFileInfo := origFile.FileInfo
+		if newFileInfo != nil {
+			newFileInfoVal := *newFileInfo
+			newFileInfoVal.Size = 0
+			newFileInfo = &newFileInfoVal
+		}
 		newFile := (&Content{
 			Destination: ToNixPath(dst),
 			Source:      ToNixPath(src),
 			Type:        origFile.Type,
-			FileInfo:    origFile.FileInfo,
+			FileInfo:    newFileInfo,
 			Packager:    origFile.Packager,
 		}).WithFileInfoDefaults()
 		if dst, err := os.Readlink(src); err == nil {


Test patch:
diff --git a/files/files_test.go b/files/files_test.go
index 9cae87d..2166267 100644
--- a/files/files_test.go
+++ b/files/files_test.go
@@ -347,3 +347,26 @@ func TestGlobbingWhenFilesHaveBrackets(t *testing.T) {
 		}
 	}
 }
+
+func TestGlobbingFilesWithDifferentSizesWithFileInfo(t *testing.T) {
+	result, err := files.ExpandContentGlobs(files.Contents{
+		{
+			Source:      "./testdata/globtest/different-sizes/**/*",
+			Destination: ".",
+			FileInfo: &files.ContentFileInfo{
+				Mode: 0o777,
+			},
+		},
+	}, false)
+	if err != nil {
+		t.Fatalf("expand content globs: %v", err)
+	}
+
+	if len(result) != 2 {
+		t.Fatalf("unexpected result length: %d, expected 2", len(result))
+	}
+
+	if result[0].FileInfo.Size == result[1].FileInfo.Size {
+		t.Fatal("test FileInfos have the same size, expected different")
+	}
+}
diff --git a/files/testdata/globtest/different-sizes/a/a.txt b/files/testdata/globtest/different-sizes/a/a.txt
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/files/testdata/globtest/different-sizes/a/a.txt
@@ -0,0 +1,1 @@
+foo
diff --git a/files/testdata/globtest/different-sizes/b/b.txt b/files/testdata/globtest/different-sizes/b/b.txt
new file mode 100644
index 0000000..15564c6
--- /dev/null
+++ b/files/testdata/globtest/different-sizes/b/b.txt
@@ -0,0 +1,1 @@
+barbaz