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:
parent
1d2e7ff616
commit
f3f9718f50
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
foo
|
|
@ -0,0 +1 @@
|
|||
barbaz
|
Loading…
Reference in New Issue