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:
Arsen6331
2022-10-27 12:28:47 +00:00
committed by GitHub
parent f649caf8f2
commit b4bd7817cd
10 changed files with 79 additions and 0 deletions
+50
View File
@@ -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 {
+4
View File
@@ -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",
+5
View File
@@ -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
View File
@@ -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
View File
@@ -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
+5
View File
@@ -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
+5
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
a
+1
View File
@@ -0,0 +1 @@
b
+1
View File
@@ -0,0 +1 @@
d