Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpm): support %config(missingok) #854

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apk/apk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func exampleInfo() *nfpm.Info {
Destination: "/etc/fake/fake2.conf",
Type: files.TypeConfigNoReplace,
},
{
Source: "../testdata/whatever.conf",
Destination: "/etc/fake/fake3.conf",
Type: files.TypeConfigMissingOK,
},
{
Destination: "/var/log/whatever",
Type: files.TypeDir,
Expand Down
2 changes: 1 addition & 1 deletion arch/arch.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func createPkginfo(info *nfpm.Info, tw *tar.Writer, totalSize int64) (*MtreeEntr
}

for _, content := range info.Contents {
if content.Type == files.TypeConfig || content.Type == files.TypeConfigNoReplace {
if content.Type == files.TypeConfig || content.Type == files.TypeConfigNoReplace || content.Type == files.TypeConfigMissingOK {
path := files.AsRelativePath(content.Destination)

if err := writeKVPair(buf, "backup", path); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ func conffiles(info *nfpm.Info) []byte {
var confs []string
for _, file := range info.Contents {
switch file.Type {
case files.TypeConfig, files.TypeConfigNoReplace:
case files.TypeConfig, files.TypeConfigNoReplace, files.TypeConfigMissingOK:
confs = append(confs, files.NormalizeAbsoluteFilePath(file.Destination))
}
}
Expand Down
5 changes: 5 additions & 0 deletions deb/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func exampleInfo() *nfpm.Info {
Destination: "/etc/fake/fake2.conf",
Type: files.TypeConfigNoReplace,
},
{
Source: "../testdata/whatever.conf",
Destination: "/etc/fake/fake3.conf",
Type: files.TypeConfigMissingOK,
},
{
Destination: "/var/log/whatever",
Type: files.TypeDir,
Expand Down
10 changes: 7 additions & 3 deletions files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ const (
// user of the package.
TypeConfig = "config"
// TypeConfigNoReplace is like TypeConfig with an added noreplace directive
// that is respected by RPM-based distributions. For all other packages it
// is handled exactly like TypeConfig.
// that is respected by RPM-based distributions.
// For all other package formats it is handled exactly like TypeConfig.
TypeConfigNoReplace = "config|noreplace"
// TypeConfigMissingOK is like TypeConfig with an added missingok directive
// that is respected by RPM-based distributions.
// For all other package formats it is handled exactly like TypeConfig.
TypeConfigMissingOK = "config|missingok"
// TypeGhost is the type of an RPM ghost file which is ignored by other packagers.
TypeRPMGhost = "ghost"
// TypeRPMDoc is the type of an RPM doc file which is ignored by other packagers.
Expand Down Expand Up @@ -289,7 +293,7 @@ func PrepareForPackager(
if err != nil {
return nil, fmt.Errorf("add tree: %w", err)
}
case TypeConfig, TypeConfigNoReplace, TypeFile, "":
case TypeConfig, TypeConfigNoReplace, TypeConfigMissingOK, TypeFile, "":
globbed, err := glob.Glob(
filepath.ToSlash(content.Source),
filepath.ToSlash(content.Destination),
Expand Down
4 changes: 2 additions & 2 deletions ipk/ipk.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func populateDataTar(info *nfpm.Info, tw *tar.Writer) (instSize int64, err error
ModTime: modtime.Get(info.MTime),
Linkname: file.Source,
})
case files.TypeFile, files.TypeTree, files.TypeConfig, files.TypeConfigNoReplace:
case files.TypeFile, files.TypeTree, files.TypeConfig, files.TypeConfigNoReplace, files.TypeConfigMissingOK:
size, err = writeFile(tw, file)
default:
// ignore everything else
Expand Down Expand Up @@ -293,7 +293,7 @@ func conffiles(info *nfpm.Info) []byte {
var confs []string
for _, file := range info.Contents {
switch file.Type {
case files.TypeConfig, files.TypeConfigNoReplace:
case files.TypeConfig, files.TypeConfigNoReplace, files.TypeConfigMissingOK:
confs = append(confs, files.NormalizeAbsoluteFilePath(file.Destination))
}
}
Expand Down
5 changes: 5 additions & 0 deletions ipk/ipk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func exampleInfo() *nfpm.Info {
Destination: "/etc/fake/fake2.conf",
Type: files.TypeConfigNoReplace,
},
{
Source: "../testdata/whatever.conf",
Destination: "/etc/fake/fake3.conf",
Type: files.TypeConfigNoReplace,
},
{
Destination: "/var/log/whatever",
Type: files.TypeDir,
Expand Down
2 changes: 2 additions & 0 deletions rpm/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ func createFilesInsideRPM(info *nfpm.Info, rpm *rpmpack.RPM) (err error) {
file, err = asRPMFile(content, rpmpack.ConfigFile)
case files.TypeConfigNoReplace:
file, err = asRPMFile(content, rpmpack.ConfigFile|rpmpack.NoReplaceFile)
case files.TypeConfigMissingOK:
file, err = asRPMFile(content, rpmpack.ConfigFile|rpmpack.MissingOkFile)
case files.TypeRPMGhost:
if content.FileInfo.Mode == 0 {
content.FileInfo.Mode = os.FileMode(0o644)
Expand Down
36 changes: 36 additions & 0 deletions rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,42 @@ func TestArches(t *testing.T) {
})
}

func TestConfigMissingOK(t *testing.T) {
var (
buildConfigFile = "../testdata/whatever.conf"
packageConfigFile = "/etc/fake/fake.conf"
)

info := &nfpm.Info{
Name: "symlink-in-files",
Arch: "amd64",
Description: "This package's config references a file via symlink.",
Version: "1.0.0",
Maintainer: "maintainer",
Overridables: nfpm.Overridables{
Contents: []*files.Content{
{
Source: buildConfigFile,
Destination: packageConfigFile,
Type: files.TypeConfigMissingOK,
},
},
},
}

var rpmFileBuffer bytes.Buffer
err := Default.Package(info, &rpmFileBuffer)
require.NoError(t, err)

expectedConfigContent, err := os.ReadFile(buildConfigFile)
require.NoError(t, err)

packageConfigContent, err := extractFileFromRpm(rpmFileBuffer.Bytes(), packageConfigFile)
require.NoError(t, err)

require.Equal(t, expectedConfigContent, packageConfigContent)
}

func TestConfigNoReplace(t *testing.T) {
var (
buildConfigFile = "../testdata/whatever.conf"
Expand Down
6 changes: 6 additions & 0 deletions www/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ contents:
dst: /etc/bar.conf
type: config|noreplace

# Corresponds to `%config(missingok)` if the packager is rpm, otherwise it
# is just a config file
- src: path/to/local/bar.conf
dst: /etc/bar.conf
type: config|missingok

# These files are not actually present in the package, but the file names
# are added to the package header. From the RPM directives documentation:
#
Expand Down
Loading