mirror of
https://github.com/goreleaser/nfpm.git
synced 2026-06-19 08:05:04 +00:00
fix: allow using directories as contents in archlinux packager (#568)
* fix: Recursively add files if content is directory * fix: Skip contents with wrong packager value * test: Add acceptance tests for directories
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -159,11 +160,60 @@ func createFilesInTar(info *nfpm.Info, tw *tar.Writer) ([]MtreeEntry, int64, err
|
||||
var entries []MtreeEntry
|
||||
var totalSize int64
|
||||
|
||||
var contents []*files.Content
|
||||
|
||||
for _, content := range info.Contents {
|
||||
if content.Packager != "" && content.Packager != packagerName {
|
||||
continue
|
||||
}
|
||||
|
||||
switch content.Type {
|
||||
case "dir", "symlink":
|
||||
contents = append(contents, content)
|
||||
continue
|
||||
}
|
||||
|
||||
fi, err := os.Stat(content.Source)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if fi.IsDir() {
|
||||
err = filepath.WalkDir(content.Source, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
relPath := strings.TrimPrefix(path, content.Source)
|
||||
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
c := &files.Content{
|
||||
Source: path,
|
||||
Destination: filepath.Join(content.Destination, relPath),
|
||||
FileInfo: &files.ContentFileInfo{
|
||||
Mode: d.Type(),
|
||||
},
|
||||
}
|
||||
|
||||
if d.Type()&os.ModeSymlink != 0 {
|
||||
c.Type = "symlink"
|
||||
}
|
||||
|
||||
contents = append(contents, c)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
} else {
|
||||
contents = append(contents, content)
|
||||
}
|
||||
}
|
||||
|
||||
for _, content := range contents {
|
||||
path := normalizePath(content.Destination)
|
||||
|
||||
switch content.Type {
|
||||
|
||||
@@ -61,6 +61,10 @@ func exampleInfo() *nfpm.Info {
|
||||
Destination: "/etc/fake/fake-link.conf",
|
||||
Type: "symlink",
|
||||
},
|
||||
{
|
||||
Source: "../testdata/something",
|
||||
Destination: "/etc/something",
|
||||
},
|
||||
},
|
||||
Scripts: nfpm.Scripts{
|
||||
PreInstall: "../testdata/scripts/preinstall.sh",
|
||||
|
||||
Vendored
+5
@@ -48,6 +48,11 @@ RUN test -f /usr/share/whatever/folder/folder2/file2
|
||||
RUN test -d /var/log/whatever
|
||||
RUN test -d /usr/share/foo
|
||||
RUN test -d /usr/foo/bar/something
|
||||
RUN test -d /etc/something
|
||||
RUN test -f /etc/something/a
|
||||
RUN test -f /etc/something/b
|
||||
RUN test -d /etc/something/c
|
||||
RUN test -f /etc/something/c/d
|
||||
RUN test $(stat -c %a /usr/sbin/fake) -eq 4755
|
||||
RUN test -f /tmp/preinstall-proof
|
||||
RUN test -f /tmp/postinstall-proof
|
||||
|
||||
+5
@@ -51,6 +51,11 @@ RUN test -f /usr/share/whatever/folder/folder2/file2
|
||||
RUN test -d /var/log/whatever
|
||||
RUN test -d /usr/share/foo
|
||||
RUN test -d /usr/foo/bar/something
|
||||
RUN test -d /etc/something
|
||||
RUN test -f /etc/something/a
|
||||
RUN test -f /etc/something/b
|
||||
RUN test -d /etc/something/c
|
||||
RUN test -f /etc/something/c/d
|
||||
RUN test $(stat -c %a /usr/bin/fake) -eq 4755
|
||||
RUN test -f /tmp/preinstall-proof
|
||||
RUN test -f /tmp/postinstall-proof
|
||||
|
||||
+2
@@ -27,6 +27,8 @@ contents:
|
||||
- src: ./testdata/whatever.conf
|
||||
dst: /etc/foo/whatever.conf
|
||||
type: config
|
||||
- src: ./testdata/something
|
||||
dst: /etc/something
|
||||
- src: ./testdata/fake
|
||||
dst: /usr/sbin/fake
|
||||
packager: deb
|
||||
|
||||
Vendored
+5
@@ -51,6 +51,11 @@ RUN test -f /usr/share/whatever/folder/folder2/file2
|
||||
RUN test -d /var/log/whatever
|
||||
RUN test -d /usr/share/foo
|
||||
RUN test -d /usr/foo/bar/something
|
||||
RUN test -d /etc/something
|
||||
RUN test -f /etc/something/a
|
||||
RUN test -f /etc/something/b
|
||||
RUN test -d /etc/something/c
|
||||
RUN test -f /etc/something/c/d
|
||||
RUN test $(stat -c %a /usr/sbin/fake) -eq 4755
|
||||
RUN test -f /tmp/preinstall-proof
|
||||
RUN test -f /tmp/postinstall-proof
|
||||
|
||||
Vendored
+5
@@ -50,6 +50,11 @@ RUN test -f /usr/share/whatever/folder/folder2/file2
|
||||
RUN test -d /var/log/whatever
|
||||
RUN test -d /usr/share/foo
|
||||
RUN test -d /usr/foo/bar/something
|
||||
RUN test -d /etc/something
|
||||
RUN test -f /etc/something/a
|
||||
RUN test -f /etc/something/b
|
||||
RUN test -d /etc/something/c
|
||||
RUN test -f /etc/something/c/d
|
||||
RUN test $(stat -c %a /usr/sbin/fake) -eq 4755
|
||||
RUN test -f /tmp/preinstall-proof
|
||||
RUN test -f /tmp/postinstall-proof
|
||||
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
a
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
b
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
d
|
||||
Reference in New Issue
Block a user