From 506e561c5d9333d8388e9abd11ff86ce299cd69d Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Tue, 14 Jun 2022 09:41:41 -0300 Subject: [PATCH 1/2] feat: remove empty_folders for good Signed-off-by: Carlos A Becker --- nfpm.go | 47 +++++++++++------------------------------------ nfpm_test.go | 8 +++++--- 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/nfpm.go b/nfpm.go index 1ad66c23..727eaa66 100644 --- a/nfpm.go +++ b/nfpm.go @@ -11,7 +11,6 @@ import ( "github.com/AlekSi/pointer" "github.com/Masterminds/semver/v3" "github.com/goreleaser/chglog" - "github.com/goreleaser/nfpm/v2/deprecation" "github.com/goreleaser/nfpm/v2/files" "github.com/imdario/mergo" "gopkg.in/yaml.v3" @@ -260,18 +259,17 @@ func (i *Info) parseSemver() { // Overridables contain the field which are overridable in a package. type Overridables struct { - Replaces []string `yaml:"replaces,omitempty" jsonschema:"title=replaces directive,example=nfpm"` - Provides []string `yaml:"provides,omitempty" jsonschema:"title=provides directive,example=nfpm"` - Depends []string `yaml:"depends,omitempty" jsonschema:"title=depends directive,example=nfpm"` - Recommends []string `yaml:"recommends,omitempty" jsonschema:"title=recommends directive,example=nfpm"` - Suggests []string `yaml:"suggests,omitempty" jsonschema:"title=suggests directive,example=nfpm"` - Conflicts []string `yaml:"conflicts,omitempty" jsonschema:"title=conflicts directive,example=nfpm"` - Contents files.Contents `yaml:"contents,omitempty" jsonschema:"title=files to add to the package"` - EmptyFolders []string `yaml:"empty_folders,omitempty" jsonschema:"title=empty folders to be created when installing the package,example=/var/log/nfpm"` // deprecated - Scripts Scripts `yaml:"scripts,omitempty" jsonschema:"title=scripts to execute"` - RPM RPM `yaml:"rpm,omitempty" jsonschema:"title=rpm-specific settings"` - Deb Deb `yaml:"deb,omitempty" jsonschema:"title=deb-specific settings"` - APK APK `yaml:"apk,omitempty" jsonschema:"title=apk-specific settings"` + Replaces []string `yaml:"replaces,omitempty" jsonschema:"title=replaces directive,example=nfpm"` + Provides []string `yaml:"provides,omitempty" jsonschema:"title=provides directive,example=nfpm"` + Depends []string `yaml:"depends,omitempty" jsonschema:"title=depends directive,example=nfpm"` + Recommends []string `yaml:"recommends,omitempty" jsonschema:"title=recommends directive,example=nfpm"` + Suggests []string `yaml:"suggests,omitempty" jsonschema:"title=suggests directive,example=nfpm"` + Conflicts []string `yaml:"conflicts,omitempty" jsonschema:"title=conflicts directive,example=nfpm"` + Contents files.Contents `yaml:"contents,omitempty" jsonschema:"title=files to add to the package"` + Scripts Scripts `yaml:"scripts,omitempty" jsonschema:"title=scripts to execute"` + RPM RPM `yaml:"rpm,omitempty" jsonschema:"title=rpm-specific settings"` + Deb Deb `yaml:"deb,omitempty" jsonschema:"title=deb-specific settings"` + APK APK `yaml:"apk,omitempty" jsonschema:"title=apk-specific settings"` } // RPM is custom configs that are only available on RPM packages. @@ -392,30 +390,7 @@ func Validate(info *Info) (err error) { return err } - if len(info.EmptyFolders) > 0 { - deprecation.Println("'empty_folders' is deprecated and " + - "will be removed in a future version, create content with type 'dir' and " + - "directory name as 'dst' instead") - - for _, emptyFolder := range info.EmptyFolders { - if contents.ContainsDestination(emptyFolder) { - return fmt.Errorf("empty folder already exists in contents: %s", emptyFolder) - } - - f := &files.Content{ - Destination: emptyFolder, - Type: "dir", - } - contents = append(contents, f.WithFileInfoDefaults()) - } - } - - // The deprecated EmptyFolders are already converted to contents, so we - // remove it such that Validate can be called more than once. - info.EmptyFolders = nil - info.Contents = contents - return nil } diff --git a/nfpm_test.go b/nfpm_test.go index 337cdc40..789531ea 100644 --- a/nfpm_test.go +++ b/nfpm_test.go @@ -111,8 +111,11 @@ func TestValidate(t *testing.T) { Arch: "asd", Version: "1.2.3", Overridables: nfpm.Overridables{ - EmptyFolders: []string{"/usr/share/test"}, Contents: []*files.Content{ + { + Destination: "/usr/share/test", + Type: "dir", + }, { Source: "./testdata/contents.yaml", Destination: "asd", @@ -121,9 +124,8 @@ func TestValidate(t *testing.T) { }, } require.NoError(t, nfpm.Validate(&info)) - require.Empty(t, info.Overridables.EmptyFolders) require.Len(t, info.Overridables.Contents, 2) - dir := info.Overridables.Contents[1] + dir := info.Overridables.Contents[0] require.Equal(t, "/usr/share/test", dir.Destination) require.Equal(t, "dir", dir.Type) require.Equal(t, "-rwxr-xr-x", dir.FileInfo.Mode.String()) From e2540d52f12477155031cf044b68e33521aadb4e Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Tue, 14 Jun 2022 09:50:31 -0300 Subject: [PATCH 2/2] fix: build Signed-off-by: Carlos A Becker --- testdata/acceptance/core.complex.yaml | 7 ++++--- testdata/acceptance/core.env-var-version.yaml | 7 ++++--- testdata/acceptance/upgrade.v1.yaml | 9 +++++---- testdata/acceptance/upgrade.v2.yaml | 9 +++++---- www/docs/static/schema.json | 14 -------------- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/testdata/acceptance/core.complex.yaml b/testdata/acceptance/core.complex.yaml index bd4ac98d..48e0114b 100644 --- a/testdata/acceptance/core.complex.yaml +++ b/testdata/acceptance/core.complex.yaml @@ -33,9 +33,10 @@ contents: mode: 04755 - dst: /usr/foo/bar/something type: dir -empty_folders: -- /var/log/whatever -- /usr/share/foo +- dst: /var/log/whatever + type: dir +- dst: /usr/share/foo + type: dir scripts: preinstall: ./testdata/acceptance/scripts/preinstall.sh postinstall: ./testdata/acceptance/scripts/postinstall.sh diff --git a/testdata/acceptance/core.env-var-version.yaml b/testdata/acceptance/core.env-var-version.yaml index 84701130..e3d872f5 100644 --- a/testdata/acceptance/core.env-var-version.yaml +++ b/testdata/acceptance/core.env-var-version.yaml @@ -25,9 +25,10 @@ contents: - src: ./testdata/whatever.conf dst: /etc/foo/whatever.conf type: config -empty_folders: - - /var/log/whatever - - /usr/share/foo +- dst: /var/log/whatever + type: dir +- dst: /usr/share/foo + type: dir scripts: preinstall: ./testdata/acceptance/scripts/preinstall.sh postinstall: ./testdata/acceptance/scripts/postinstall.sh diff --git a/testdata/acceptance/upgrade.v1.yaml b/testdata/acceptance/upgrade.v1.yaml index 80194032..bcbed9e2 100644 --- a/testdata/acceptance/upgrade.v1.yaml +++ b/testdata/acceptance/upgrade.v1.yaml @@ -26,9 +26,10 @@ contents: - src: ./testdata/whatever.conf dst: /etc/noreplace.conf type: config|noreplace -empty_folders: - - /var/log/whatever - - /usr/share/foo + - dst: /var/log/whatever + type: dir + - dst: /usr/share/foo + type: dir scripts: preinstall: ./testdata/acceptance/scripts/preinstall.sh postinstall: ./testdata/acceptance/scripts/postinstall.sh @@ -37,4 +38,4 @@ scripts: apk: scripts: preupgrade: ./testdata/acceptance/scripts/preupgrade.sh - postupgrade: ./testdata/acceptance/scripts/postupgrade.sh \ No newline at end of file + postupgrade: ./testdata/acceptance/scripts/postupgrade.sh diff --git a/testdata/acceptance/upgrade.v2.yaml b/testdata/acceptance/upgrade.v2.yaml index 3bd830b6..09c11723 100644 --- a/testdata/acceptance/upgrade.v2.yaml +++ b/testdata/acceptance/upgrade.v2.yaml @@ -26,9 +26,10 @@ contents: - src: ./testdata/whatever2.conf dst: /etc/noreplace.conf type: config|noreplace -empty_folders: - - /var/log/whatever - - /usr/share/foo + - dst: /var/log/whatever + type: dir + - dst: /usr/share/foo + type: dir scripts: preinstall: ./testdata/acceptance/scripts/preinstall.sh postinstall: ./testdata/acceptance/scripts/postinstall.sh @@ -37,4 +38,4 @@ scripts: apk: scripts: preupgrade: ./testdata/acceptance/scripts/preupgrade.sh - postupgrade: ./testdata/acceptance/scripts/postupgrade.sh \ No newline at end of file + postupgrade: ./testdata/acceptance/scripts/postupgrade.sh diff --git a/www/docs/static/schema.json b/www/docs/static/schema.json index 145875ac..dd969f5f 100644 --- a/www/docs/static/schema.json +++ b/www/docs/static/schema.json @@ -114,13 +114,6 @@ "type": "array", "title": "files to add to the package" }, - "empty_folders": { - "items": { - "type": "string" - }, - "type": "array", - "title": "empty folders to be created when installing the package" - }, "scripts": { "$ref": "#/$defs/Scripts", "title": "scripts to execute" @@ -529,13 +522,6 @@ "type": "array", "title": "files to add to the package" }, - "empty_folders": { - "items": { - "type": "string" - }, - "type": "array", - "title": "empty folders to be created when installing the package" - }, "scripts": { "$ref": "#/$defs/Scripts", "title": "scripts to execute"