Skip to content

Commit fa30aa2

Browse files
authored
feat(rpm): support %config(missingok) (#854)
* feat(rpm): support %config(missingok) closes #853 * Update files/files.go
1 parent cbb71bf commit fa30aa2

File tree

10 files changed

+70
-7
lines changed

10 files changed

+70
-7
lines changed

apk/apk_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ func exampleInfo() *nfpm.Info {
8181
Destination: "/etc/fake/fake2.conf",
8282
Type: files.TypeConfigNoReplace,
8383
},
84+
{
85+
Source: "../testdata/whatever.conf",
86+
Destination: "/etc/fake/fake3.conf",
87+
Type: files.TypeConfigMissingOK,
88+
},
8489
{
8590
Destination: "/var/log/whatever",
8691
Type: files.TypeDir,

arch/arch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func createPkginfo(info *nfpm.Info, tw *tar.Writer, totalSize int64) (*MtreeEntr
359359
}
360360

361361
for _, content := range info.Contents {
362-
if content.Type == files.TypeConfig || content.Type == files.TypeConfigNoReplace {
362+
if content.Type == files.TypeConfig || content.Type == files.TypeConfigNoReplace || content.Type == files.TypeConfigMissingOK {
363363
path := files.AsRelativePath(content.Destination)
364364

365365
if err := writeKVPair(buf, "backup", path); err != nil {

deb/deb.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ func conffiles(info *nfpm.Info) []byte {
681681
var confs []string
682682
for _, file := range info.Contents {
683683
switch file.Type {
684-
case files.TypeConfig, files.TypeConfigNoReplace:
684+
case files.TypeConfig, files.TypeConfigNoReplace, files.TypeConfigMissingOK:
685685
confs = append(confs, files.NormalizeAbsoluteFilePath(file.Destination))
686686
}
687687
}

deb/deb_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func exampleInfo() *nfpm.Info {
8585
Destination: "/etc/fake/fake2.conf",
8686
Type: files.TypeConfigNoReplace,
8787
},
88+
{
89+
Source: "../testdata/whatever.conf",
90+
Destination: "/etc/fake/fake3.conf",
91+
Type: files.TypeConfigMissingOK,
92+
},
8893
{
8994
Destination: "/var/log/whatever",
9095
Type: files.TypeDir,

files/files.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ const (
3232
// user of the package.
3333
TypeConfig = "config"
3434
// TypeConfigNoReplace is like TypeConfig with an added noreplace directive
35-
// that is respected by RPM-based distributions. For all other packages it
36-
// is handled exactly like TypeConfig.
35+
// that is respected by RPM-based distributions.
36+
// For all other package formats it is handled exactly like TypeConfig.
3737
TypeConfigNoReplace = "config|noreplace"
38+
// TypeConfigMissingOK is like TypeConfig with an added missingok directive
39+
// that is respected by RPM-based distributions.
40+
// For all other package formats it is handled exactly like TypeConfig.
41+
TypeConfigMissingOK = "config|missingok"
3842
// TypeGhost is the type of an RPM ghost file which is ignored by other packagers.
3943
TypeRPMGhost = "ghost"
4044
// TypeRPMDoc is the type of an RPM doc file which is ignored by other packagers.
@@ -289,7 +293,7 @@ func PrepareForPackager(
289293
if err != nil {
290294
return nil, fmt.Errorf("add tree: %w", err)
291295
}
292-
case TypeConfig, TypeConfigNoReplace, TypeFile, "":
296+
case TypeConfig, TypeConfigNoReplace, TypeConfigMissingOK, TypeFile, "":
293297
globbed, err := glob.Glob(
294298
filepath.ToSlash(content.Source),
295299
filepath.ToSlash(content.Destination),

ipk/ipk.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func populateDataTar(info *nfpm.Info, tw *tar.Writer) (instSize int64, err error
205205
ModTime: modtime.Get(info.MTime),
206206
Linkname: file.Source,
207207
})
208-
case files.TypeFile, files.TypeTree, files.TypeConfig, files.TypeConfigNoReplace:
208+
case files.TypeFile, files.TypeTree, files.TypeConfig, files.TypeConfigNoReplace, files.TypeConfigMissingOK:
209209
size, err = writeFile(tw, file)
210210
default:
211211
// ignore everything else
@@ -293,7 +293,7 @@ func conffiles(info *nfpm.Info) []byte {
293293
var confs []string
294294
for _, file := range info.Contents {
295295
switch file.Type {
296-
case files.TypeConfig, files.TypeConfigNoReplace:
296+
case files.TypeConfig, files.TypeConfigNoReplace, files.TypeConfigMissingOK:
297297
confs = append(confs, files.NormalizeAbsoluteFilePath(file.Destination))
298298
}
299299
}

ipk/ipk_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ func exampleInfo() *nfpm.Info {
7171
Destination: "/etc/fake/fake2.conf",
7272
Type: files.TypeConfigNoReplace,
7373
},
74+
{
75+
Source: "../testdata/whatever.conf",
76+
Destination: "/etc/fake/fake3.conf",
77+
Type: files.TypeConfigNoReplace,
78+
},
7479
{
7580
Destination: "/var/log/whatever",
7681
Type: files.TypeDir,

rpm/rpm.go

+2
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ func createFilesInsideRPM(info *nfpm.Info, rpm *rpmpack.RPM) (err error) {
373373
file, err = asRPMFile(content, rpmpack.ConfigFile)
374374
case files.TypeConfigNoReplace:
375375
file, err = asRPMFile(content, rpmpack.ConfigFile|rpmpack.NoReplaceFile)
376+
case files.TypeConfigMissingOK:
377+
file, err = asRPMFile(content, rpmpack.ConfigFile|rpmpack.MissingOkFile)
376378
case files.TypeRPMGhost:
377379
if content.FileInfo.Mode == 0 {
378380
content.FileInfo.Mode = os.FileMode(0o644)

rpm/rpm_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,42 @@ func TestArches(t *testing.T) {
595595
})
596596
}
597597

598+
func TestConfigMissingOK(t *testing.T) {
599+
var (
600+
buildConfigFile = "../testdata/whatever.conf"
601+
packageConfigFile = "/etc/fake/fake.conf"
602+
)
603+
604+
info := &nfpm.Info{
605+
Name: "symlink-in-files",
606+
Arch: "amd64",
607+
Description: "This package's config references a file via symlink.",
608+
Version: "1.0.0",
609+
Maintainer: "maintainer",
610+
Overridables: nfpm.Overridables{
611+
Contents: []*files.Content{
612+
{
613+
Source: buildConfigFile,
614+
Destination: packageConfigFile,
615+
Type: files.TypeConfigMissingOK,
616+
},
617+
},
618+
},
619+
}
620+
621+
var rpmFileBuffer bytes.Buffer
622+
err := Default.Package(info, &rpmFileBuffer)
623+
require.NoError(t, err)
624+
625+
expectedConfigContent, err := os.ReadFile(buildConfigFile)
626+
require.NoError(t, err)
627+
628+
packageConfigContent, err := extractFileFromRpm(rpmFileBuffer.Bytes(), packageConfigFile)
629+
require.NoError(t, err)
630+
631+
require.Equal(t, expectedConfigContent, packageConfigContent)
632+
}
633+
598634
func TestConfigNoReplace(t *testing.T) {
599635
var (
600636
buildConfigFile = "../testdata/whatever.conf"

www/docs/configuration.md

+6
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ contents:
209209
dst: /etc/bar.conf
210210
type: config|noreplace
211211

212+
# Corresponds to `%config(missingok)` if the packager is rpm, otherwise it
213+
# is just a config file
214+
- src: path/to/local/bar.conf
215+
dst: /etc/bar.conf
216+
type: config|missingok
217+
212218
# These files are not actually present in the package, but the file names
213219
# are added to the package header. From the RPM directives documentation:
214220
#

0 commit comments

Comments
 (0)