mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-01 13:07:49 +02:00
fix(nfpm): write too long when writing the lintian file (#4039)
The lintian files were being written for every format, whether they were a deb or not. Since package name and arches are the same, and packaging runs in parallel, it could happen that one goroutine is reading while the other is writing, as we were guaranteeing uniquenes based on package name and arch only. This makes it only creates the lintian files when format is deb, so this shouldn't happen anymore. It also goes one step further by using the actual format in the filepath instead of hard-coding "deb". This also still supports tmux. closes #4024
This commit is contained in:
parent
98ca0679a1
commit
b9e276feca
@ -252,28 +252,12 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar
|
||||
})
|
||||
}
|
||||
|
||||
if len(fpm.Deb.Lintian) > 0 {
|
||||
lines := make([]string, 0, len(fpm.Deb.Lintian))
|
||||
for _, ov := range fpm.Deb.Lintian {
|
||||
lines = append(lines, fmt.Sprintf("%s: %s", packageName, ov))
|
||||
if len(fpm.Deb.Lintian) > 0 && (format == "deb" || format == "termux.deb") {
|
||||
lintian, err := setupLintian(ctx, fpm, packageName, format, arch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lintianPath := filepath.Join(ctx.Config.Dist, "deb", packageName+"_"+arch, ".lintian")
|
||||
if err := os.MkdirAll(filepath.Dir(lintianPath), 0o755); err != nil {
|
||||
return fmt.Errorf("failed to write lintian file: %w", err)
|
||||
}
|
||||
if err := os.WriteFile(lintianPath, []byte(strings.Join(lines, "\n")), 0o644); err != nil {
|
||||
return fmt.Errorf("failed to write lintian file: %w", err)
|
||||
}
|
||||
|
||||
log.Debugf("creating %q", lintianPath)
|
||||
contents = append(contents, &files.Content{
|
||||
Source: lintianPath,
|
||||
Destination: filepath.Join("./usr/share/lintian/overrides", packageName),
|
||||
Packager: "deb",
|
||||
FileInfo: &files.ContentFileInfo{
|
||||
Mode: 0o644,
|
||||
},
|
||||
})
|
||||
contents = append(contents, lintian)
|
||||
}
|
||||
|
||||
log := log.WithField("package", packageName).WithField("format", format).WithField("arch", arch)
|
||||
@ -456,6 +440,30 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar
|
||||
return nil
|
||||
}
|
||||
|
||||
func setupLintian(ctx *context.Context, fpm config.NFPM, packageName, format, arch string) (*files.Content, error) {
|
||||
lines := make([]string, 0, len(fpm.Deb.Lintian))
|
||||
for _, ov := range fpm.Deb.Lintian {
|
||||
lines = append(lines, fmt.Sprintf("%s: %s", packageName, ov))
|
||||
}
|
||||
lintianPath := filepath.Join(ctx.Config.Dist, format, packageName+"_"+arch, "lintian")
|
||||
if err := os.MkdirAll(filepath.Dir(lintianPath), 0o755); err != nil {
|
||||
return nil, fmt.Errorf("failed to write lintian file: %w", err)
|
||||
}
|
||||
if err := os.WriteFile(lintianPath, []byte(strings.Join(lines, "\n")), 0o644); err != nil {
|
||||
return nil, fmt.Errorf("failed to write lintian file: %w", err)
|
||||
}
|
||||
|
||||
log.Debugf("creating %q", lintianPath)
|
||||
return &files.Content{
|
||||
Source: lintianPath,
|
||||
Destination: filepath.Join("./usr/share/lintian/overrides", packageName),
|
||||
Packager: "deb",
|
||||
FileInfo: &files.ContentFileInfo{
|
||||
Mode: 0o644,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func destinations(contents files.Contents) []string {
|
||||
result := make([]string, 0, len(contents))
|
||||
for _, f := range contents {
|
||||
|
@ -860,20 +860,50 @@ func TestDebSpecificConfig(t *testing.T) {
|
||||
|
||||
t.Run("lintian", func(t *testing.T) {
|
||||
ctx := setupContext(t)
|
||||
ctx.Parallelism = 100
|
||||
ctx.Env = map[string]string{
|
||||
"NFPM_SOMEID_DEB_PASSPHRASE": "hunter2",
|
||||
}
|
||||
ctx.Config.NFPMs[0].NFPMOverridables.Deb.Lintian = []string{
|
||||
ctx.Config.NFPMs[0].Deb.Lintian = []string{
|
||||
"statically-linked-binary",
|
||||
"changelog-file-missing-in-native-package",
|
||||
}
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
ctx.Config.NFPMs[0].Formats = []string{"apk", "rpm", "deb", "termux.deb"}
|
||||
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
for _, format := range []string{"apk", "rpm"} {
|
||||
require.NoDirExists(t, filepath.Join(ctx.Config.Dist, format))
|
||||
}
|
||||
require.DirExists(t, filepath.Join(ctx.Config.Dist, "deb"))
|
||||
for _, goarch := range []string{"amd64", "386"} {
|
||||
bts, err := os.ReadFile(filepath.Join(ctx.Config.Dist, "deb/foo_"+goarch+"/.lintian"))
|
||||
bts, err := os.ReadFile(filepath.Join(ctx.Config.Dist, "deb", "foo_"+goarch, "lintian"))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "foo: statically-linked-binary\nfoo: changelog-file-missing-in-native-package", string(bts))
|
||||
}
|
||||
require.DirExists(t, filepath.Join(ctx.Config.Dist, "termux.deb"))
|
||||
for _, goarch := range []string{"x86_64", "i686"} {
|
||||
bts, err := os.ReadFile(filepath.Join(ctx.Config.Dist, "termux.deb", "foo_"+goarch, "lintian"))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "foo: statically-linked-binary\nfoo: changelog-file-missing-in-native-package", string(bts))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("lintian no debs", func(t *testing.T) {
|
||||
ctx := setupContext(t)
|
||||
ctx.Parallelism = 100
|
||||
ctx.Env = map[string]string{
|
||||
"NFPM_SOMEID_DEB_PASSPHRASE": "hunter2",
|
||||
}
|
||||
ctx.Config.NFPMs[0].Deb.Lintian = []string{
|
||||
"statically-linked-binary",
|
||||
"changelog-file-missing-in-native-package",
|
||||
}
|
||||
ctx.Config.NFPMs[0].Formats = []string{"apk", "rpm"}
|
||||
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
for _, format := range []string{"deb", "termux.deb"} {
|
||||
require.NoDirExists(t, filepath.Join(ctx.Config.Dist, format))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user