diff --git a/files/files.go b/files/files.go index 776949d6..68fe6a30 100644 --- a/files/files.go +++ b/files/files.go @@ -490,6 +490,9 @@ func addTree( c.Destination = NormalizeAbsoluteDirPath(destination) c.FileInfo.Mode = info.Mode() &^ umask c.FileInfo.MTime = info.ModTime() + if ownedByFilesystem(c.Destination) { + c.Type = TypeImplicitDir + } case d.Type()&os.ModeSymlink != 0: linkDestination, err := os.Readlink(path) if err != nil { diff --git a/files/files_test.go b/files/files_test.go index 16a4182d..6474687b 100644 --- a/files/files_test.go +++ b/files/files_test.go @@ -974,3 +974,68 @@ func TestAsExplicitRelativePath(t *testing.T) { assert.Equal(t, expected, files.AsExplicitRelativePath(input)) } } + +func TestIssue829(t *testing.T) { + var config testStruct + dec := yaml.NewDecoder(strings.NewReader(`--- +contents: + # Implementation. + - src: ./testdata/issue829/lib/ + dst: /usr/lib/ + type: tree + - src: ./testdata/issue829/usr/ + dst: /usr/ + type: tree + - src: ./testdata/issue829/var/ + dst: /var/ + type: tree + + # Configuration. + - src: ./testdata/issue829/etc/logrotate.d/acme + dst: /etc/logrotate.d/acme + type: config|noreplace + - src: ./testdata/issue829/etc/sysconfig/acme + dst: /etc/sysconfig/acme + type: config|noreplace +`)) + dec.KnownFields(true) + require.NoError(t, dec.Decode(&config)) + files, err := files.PrepareForPackager( + config.Contents, + 0, + "", + false, + mtime, + ) + require.NoError(t, err) + + expect := map[string]string{ + "/etc/": "implicit dir", + "/etc/logrotate.d/": "implicit dir", + "/etc/logrotate.d/acme": "config|noreplace", + "/etc/sysconfig/": "implicit dir", + "/etc/sysconfig/acme": "config|noreplace", + "/usr/lib/": "implicit dir", + "/usr/lib/systemd/": "implicit dir", + "/usr/lib/systemd/system/": "implicit dir", + "/usr/lib/systemd/system/acme.service": "file", + "/usr/": "implicit dir", + "/usr/bin/": "implicit dir", + "/usr/bin/acme": "file", + "/usr/share/": "implicit dir", + "/usr/share/doc/": "implicit dir", + "/usr/share/doc/acme/": "dir", + "/usr/share/doc/acme/readme.md": "file", + "/usr/share/man/": "implicit dir", + "/usr/share/man/man1/": "implicit dir", + "/usr/share/man/man1/acme.1.gz": "file", + "/var/": "implicit dir", + "/var/log/": "implicit dir", + "/var/log/acme/": "dir", + "/var/log/acme/.gitkeep": "file", + } + + for _, file := range files { + require.Equal(t, expect[file.Destination], file.Type, "invalid type for %s", file.Destination) + } +} diff --git a/files/fs.go b/files/fs.go index 1e966474..580e99ad 100644 --- a/files/fs.go +++ b/files/fs.go @@ -4,7 +4,7 @@ import "path/filepath" func ownedByFilesystem(path string) bool { p := filepath.Clean(path) - for _, pp := range fsPaths { + for _, pp := range append(fsPaths, logrotatePaths...) { if p == pp { return true } @@ -12,7 +12,9 @@ func ownedByFilesystem(path string) bool { return false } -// from: repoquery --installed -l filesystem | while read -r f; do test -d $f && echo $f; done +// yum install yum-utils + +// repoquery --installed -l filesystem | while read -r f; do test -d "\"$f\"," && echo $f; done var fsPaths = []string{ "/afs", "/bin", @@ -213,3 +215,12 @@ var fsPaths = []string{ "/var/tmp", "/var/yp", } + +// repoquery --installed -l logrotate | while read -r f; do test -d "\"$f\"," && echo $f; done +var logrotatePaths = []string{ + "/etc/logrotate.d", + "/usr/lib/.build-id", + "/usr/lib/.build-id/ae", + "/usr/share/licenses/logrotate", + "/var/lib/logrotate", +} diff --git a/files/testdata/issue829/etc/logrotate.d/acme b/files/testdata/issue829/etc/logrotate.d/acme new file mode 100644 index 00000000..e69de29b diff --git a/files/testdata/issue829/etc/sysconfig/acme b/files/testdata/issue829/etc/sysconfig/acme new file mode 100644 index 00000000..e69de29b diff --git a/files/testdata/issue829/lib/systemd/system/acme.service b/files/testdata/issue829/lib/systemd/system/acme.service new file mode 100644 index 00000000..e69de29b diff --git a/files/testdata/issue829/usr/share/doc/acme/readme.md b/files/testdata/issue829/usr/share/doc/acme/readme.md new file mode 100644 index 00000000..e69de29b diff --git a/files/testdata/issue829/usr/share/man/man1/acme.1.gz b/files/testdata/issue829/usr/share/man/man1/acme.1.gz new file mode 100644 index 00000000..e69de29b diff --git a/files/testdata/issue829/var/log/acme/.gitkeep b/files/testdata/issue829/var/log/acme/.gitkeep new file mode 100644 index 00000000..e69de29b