1
1
Fork 0
mirror of https://github.com/goreleaser/nfpm synced 2024-04-20 13:24:01 +02:00

fix: ensure globbed FileInfo always has correct size (#482)

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.
This commit is contained in:
Marks Polakovs 2022-03-25 01:40:07 +00:00 committed by GitHub
parent 1d2e7ff616
commit f3f9718f50
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 1 deletions

View File

@ -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 {

View File

@ -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")
}
}

View File

@ -0,0 +1 @@
foo

View File

@ -0,0 +1 @@
barbaz