Skip to content

Commit

Permalink
fix: properly handle files owned by fs (#760)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Jan 5, 2024
1 parent 37b28fd commit beb0f73
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 10 deletions.
2 changes: 1 addition & 1 deletion files/files.go
Expand Up @@ -474,7 +474,7 @@ func addTree(
c := &Content{
FileInfo: &ContentFileInfo{},
}
if tree.FileInfo != nil {
if tree.FileInfo != nil && !ownedByFilesystem(tree.Destination) {
c.FileInfo.Owner = tree.FileInfo.Owner
c.FileInfo.Group = tree.FileInfo.Group
}
Expand Down
33 changes: 24 additions & 9 deletions files/files_test.go
Expand Up @@ -756,7 +756,7 @@ func TestTreeOwner(t *testing.T) {
files.Contents{
{
Source: filepath.Join("testdata", "tree"),
Destination: "/base",
Destination: "/usr/share/foo",
Type: files.TypeTree,
FileInfo: &files.ContentFileInfo{
Owner: "goreleaser",
Expand All @@ -773,49 +773,64 @@ func TestTreeOwner(t *testing.T) {
require.NoError(t, err)

for _, f := range results {
if f.Destination == "/usr/" || f.Destination == "/usr/share/" {
require.Equal(t, "root", f.FileInfo.Owner, f.Destination)
require.Equal(t, "root", f.FileInfo.Group, f.Destination)
continue
}
require.Equal(t, "goreleaser", f.FileInfo.Owner, f.Destination)
require.Equal(t, "goreleaser", f.FileInfo.Group, f.Destination)
}

require.Equal(t, files.Contents{
{
Source: "",
Destination: "/base/",
Destination: "/usr/",
Type: files.TypeImplicitDir,
},
{
Source: "",
Destination: "/usr/share/",
Type: files.TypeImplicitDir,
},
{
Source: "",
Destination: "/usr/share/foo/",
Type: files.TypeDir,
},
{
Source: "",
Destination: "/base/files/",
Destination: "/usr/share/foo/files/",
Type: files.TypeDir,
},
{
Source: filepath.Join("testdata", "tree", "files", "a"),
Destination: "/base/files/a",
Destination: "/usr/share/foo/files/a",
Type: files.TypeFile,
},
{
Source: "",
Destination: "/base/files/b/",
Destination: "/usr/share/foo/files/b/",
Type: files.TypeDir,
},
{
Source: filepath.Join("testdata", "tree", "files", "b", "c"),
Destination: "/base/files/b/c",
Destination: "/usr/share/foo/files/b/c",
Type: files.TypeFile,
},
{
Source: "",
Destination: "/base/symlinks/",
Destination: "/usr/share/foo/symlinks/",
Type: files.TypeDir,
},
{
Source: "/etc/foo",
Destination: "/base/symlinks/link1",
Destination: "/usr/share/foo/symlinks/link1",
Type: files.TypeSymlink,
},
{
Source: "../files/a",
Destination: "/base/symlinks/link2",
Destination: "/usr/share/foo/symlinks/link2",
Type: files.TypeSymlink,
},
}, withoutFileInfo(results))
Expand Down
215 changes: 215 additions & 0 deletions files/fs.go
@@ -0,0 +1,215 @@
package files

import "path/filepath"

func ownedByFilesystem(path string) bool {
p := filepath.Clean(path)
for _, pp := range fsPaths {
if p == pp {
return true
}
}
return false
}

// from: repoquery --installed -l filesystem | while read -r f; do test -d $f && echo $f; done
var fsPaths = []string{
"/afs",
"/bin",
"/boot",
"/dev",
"/etc",
"/etc/X11",
"/etc/X11/applnk",
"/etc/X11/fontpath.d",
"/etc/X11/xinit",
"/etc/X11/xinit/xinitrc.d",
"/etc/X11/xinit/xinput.d",
"/etc/bash_completion.d",
"/etc/keys",
"/etc/keys/ima",
"/etc/opt",
"/etc/pki",
"/etc/pm",
"/etc/pm/config.d",
"/etc/pm/power.d",
"/etc/pm/sleep.d",
"/etc/rwtab.d",
"/etc/skel",
"/etc/statetab.d",
"/etc/sysconfig",
"/etc/xdg",
"/etc/xdg/autostart",
"/home",
"/lib",
"/lib64",
"/media",
"/mnt",
"/opt",
"/proc",
"/root",
"/run",
"/sbin",
"/srv",
"/sys",
"/tmp",
"/usr",
"/usr/bin",
"/usr/games",
"/usr/include",
"/usr/lib",
"/usr/lib/debug",
"/usr/lib/debug/.dwz",
"/usr/lib/debug/bin",
"/usr/lib/debug/lib",
"/usr/lib/debug/lib64",
"/usr/lib/debug/sbin",
"/usr/lib/debug/usr",
"/usr/lib/debug/usr/.dwz",
"/usr/lib/debug/usr/bin",
"/usr/lib/debug/usr/lib",
"/usr/lib/debug/usr/lib64",
"/usr/lib/debug/usr/sbin",
"/usr/lib/games",
"/usr/lib/locale",
"/usr/lib/modules",
"/usr/lib/sysimage",
"/usr/lib/systemd",
"/usr/lib/systemd/system",
"/usr/lib/systemd/user",
"/usr/lib/sysusers.d",
"/usr/lib/tmpfiles.d",
"/usr/lib64",
"/usr/lib64/X11",
"/usr/lib64/bpf",
"/usr/lib64/games",
"/usr/lib64/pm-utils",
"/usr/lib64/pm-utils/module.d",
"/usr/lib64/pm-utils/power.d",
"/usr/lib64/pm-utils/sleep.d",
"/usr/libexec",
"/usr/local",
"/usr/local/bin",
"/usr/local/etc",
"/usr/local/games",
"/usr/local/include",
"/usr/local/lib",
"/usr/local/lib64",
"/usr/local/lib64/bpf",
"/usr/local/libexec",
"/usr/local/sbin",
"/usr/local/share",
"/usr/local/share/applications",
"/usr/local/share/info",
"/usr/local/share/man",
"/usr/local/share/man/man1",
"/usr/local/share/man/man1x",
"/usr/local/share/man/man2",
"/usr/local/share/man/man2x",
"/usr/local/share/man/man3",
"/usr/local/share/man/man3x",
"/usr/local/share/man/man4",
"/usr/local/share/man/man4x",
"/usr/local/share/man/man5",
"/usr/local/share/man/man5x",
"/usr/local/share/man/man6",
"/usr/local/share/man/man6x",
"/usr/local/share/man/man7",
"/usr/local/share/man/man7x",
"/usr/local/share/man/man8",
"/usr/local/share/man/man8x",
"/usr/local/share/man/man9",
"/usr/local/share/man/man9x",
"/usr/local/share/man/mann",
"/usr/local/src",
"/usr/sbin",
"/usr/share",
"/usr/share/X11",
"/usr/share/X11/fonts",
"/usr/share/aclocal",
"/usr/share/appdata",
"/usr/share/applications",
"/usr/share/augeas",
"/usr/share/augeas/lenses",
"/usr/share/backgrounds",
"/usr/share/bash-completion",
"/usr/share/bash-completion/completions",
"/usr/share/bash-completion/helpers",
"/usr/share/desktop-directories",
"/usr/share/dict",
"/usr/share/doc",
"/usr/share/empty",
"/usr/share/fish",
"/usr/share/fish/vendor_completions.d",
"/usr/share/games",
"/usr/share/gnome",
"/usr/share/help",
"/usr/share/icons",
"/usr/share/idl",
"/usr/share/info",
"/usr/share/licenses",
"/usr/share/locale",
"/usr/share/locale/en_US",
"/usr/share/locale/en_US/LC_MESSAGES",
"/usr/share/man",
"/usr/share/man/man0p",
"/usr/share/man/man1",
"/usr/share/man/man1p",
"/usr/share/man/man1x",
"/usr/share/man/man2",
"/usr/share/man/man2x",
"/usr/share/man/man3",
"/usr/share/man/man3p",
"/usr/share/man/man3x",
"/usr/share/man/man4",
"/usr/share/man/man4x",
"/usr/share/man/man5",
"/usr/share/man/man5x",
"/usr/share/man/man6",
"/usr/share/man/man6x",
"/usr/share/man/man7",
"/usr/share/man/man7x",
"/usr/share/man/man8",
"/usr/share/man/man8x",
"/usr/share/man/man9",
"/usr/share/man/man9x",
"/usr/share/man/mann",
"/usr/share/metainfo",
"/usr/share/mime-info",
"/usr/share/misc",
"/usr/share/omf",
"/usr/share/pixmaps",
"/usr/share/sounds",
"/usr/share/themes",
"/usr/share/wayland-sessions",
"/usr/share/xsessions",
"/usr/share/zsh",
"/usr/share/zsh/site-functions",
"/usr/src",
"/usr/src/debug",
"/usr/src/kernels",
"/usr/tmp",
"/var",
"/var/adm",
"/var/cache",
"/var/db",
"/var/empty",
"/var/ftp",
"/var/games",
"/var/lib",
"/var/lib/games",
"/var/lib/misc",
"/var/lib/rpm-state",
"/var/local",
"/var/log",
"/var/mail",
"/var/nis",
"/var/opt",
"/var/preserve",
"/var/run",
"/var/spool",
"/var/spool/lpd",
"/var/spool/mail",
"/var/tmp",
"/var/yp",
}

0 comments on commit beb0f73

Please sign in to comment.