Skip to content

Commit

Permalink
fix: use parent owner/group on typedir (#754)
Browse files Browse the repository at this point in the history
closes #738
  • Loading branch information
caarlos0 authored Dec 20, 2023
1 parent d56350e commit cdd9a62
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 12 deletions.
24 changes: 12 additions & 12 deletions files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,13 @@ func addTree(

destination := filepath.Join(tree.Destination, relPath)

c := &Content{}
c := &Content{
FileInfo: &ContentFileInfo{},
}
if tree.FileInfo != nil {
c.FileInfo.Owner = tree.FileInfo.Owner
c.FileInfo.Group = tree.FileInfo.Group
}

switch {
case d.IsDir():
Expand All @@ -482,28 +488,22 @@ func addTree(

c.Type = TypeDir
c.Destination = NormalizeAbsoluteDirPath(destination)
c.FileInfo = &ContentFileInfo{
Owner: "root",
Group: "root",
Mode: info.Mode() &^ umask,
MTime: info.ModTime(),
}
c.FileInfo.Mode = info.Mode() &^ umask
c.FileInfo.MTime = info.ModTime()
case d.Type()&os.ModeSymlink != 0:
linkDestination, err := os.Readlink(path)
if err != nil {
return err
}

c.Type = TypeSymlink
c.Source = filepath.ToSlash(strings.TrimPrefix(linkDestination, filepath.VolumeName(linkDestination)))
c.Destination = NormalizeAbsoluteFilePath(destination)
c.Type = TypeSymlink
default:
c.Type = TypeFile
c.Source = path
c.Destination = NormalizeAbsoluteFilePath(destination)
c.Type = TypeFile
c.FileInfo = &ContentFileInfo{
Mode: d.Type() &^ umask,
}
c.FileInfo.Mode = d.Type() &^ umask
}

all[c.Destination] = c.WithFileInfoDefaults(umask, mtime)
Expand Down
70 changes: 70 additions & 0 deletions files/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,76 @@ func TestRelevantFiles(t *testing.T) {
})
}

func TestTreeOwner(t *testing.T) {
results, err := files.PrepareForPackager(
files.Contents{
{
Source: filepath.Join("testdata", "tree"),
Destination: "/base",
Type: files.TypeTree,
FileInfo: &files.ContentFileInfo{
Owner: "goreleaser",
Group: "goreleaser",
MTime: mtime,
},
},
},
0,
"",
false,
mtime,
)
require.NoError(t, err)

for _, f := range results {
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/",
Type: files.TypeDir,
},
{
Source: "",
Destination: "/base/files/",
Type: files.TypeDir,
},
{
Source: filepath.Join("testdata", "tree", "files", "a"),
Destination: "/base/files/a",
Type: files.TypeFile,
},
{
Source: "",
Destination: "/base/files/b/",
Type: files.TypeDir,
},
{
Source: filepath.Join("testdata", "tree", "files", "b", "c"),
Destination: "/base/files/b/c",
Type: files.TypeFile,
},
{
Source: "",
Destination: "/base/symlinks/",
Type: files.TypeDir,
},
{
Source: "/etc/foo",
Destination: "/base/symlinks/link1",
Type: files.TypeSymlink,
},
{
Source: "../files/a",
Destination: "/base/symlinks/link2",
Type: files.TypeSymlink,
},
}, withoutFileInfo(results))
}

func TestTree(t *testing.T) {
results, err := files.PrepareForPackager(
files.Contents{
Expand Down

0 comments on commit cdd9a62

Please sign in to comment.