Skip to content

Commit

Permalink
feat: remove empty_folders for good (#522)
Browse files Browse the repository at this point in the history
* feat: remove empty_folders for good

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: build

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Jun 14, 2022
1 parent 8e17486 commit 1e0d944
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 67 deletions.
47 changes: 11 additions & 36 deletions nfpm.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions nfpm_test.go
Expand Up @@ -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",
Expand All @@ -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())
Expand Down
7 changes: 4 additions & 3 deletions testdata/acceptance/core.complex.yaml
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions testdata/acceptance/core.env-var-version.yaml
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions testdata/acceptance/upgrade.v1.yaml
Expand Up @@ -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
Expand All @@ -37,4 +38,4 @@ scripts:
apk:
scripts:
preupgrade: ./testdata/acceptance/scripts/preupgrade.sh
postupgrade: ./testdata/acceptance/scripts/postupgrade.sh
postupgrade: ./testdata/acceptance/scripts/postupgrade.sh
9 changes: 5 additions & 4 deletions testdata/acceptance/upgrade.v2.yaml
Expand Up @@ -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
Expand All @@ -37,4 +38,4 @@ scripts:
apk:
scripts:
preupgrade: ./testdata/acceptance/scripts/preupgrade.sh
postupgrade: ./testdata/acceptance/scripts/postupgrade.sh
postupgrade: ./testdata/acceptance/scripts/postupgrade.sh
14 changes: 0 additions & 14 deletions www/docs/static/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1e0d944

Please sign in to comment.