Skip to content

Commit

Permalink
fix: file mode when type: tree (#779)
Browse files Browse the repository at this point in the history
closes #777

Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 authored Jan 31, 2024
1 parent 48d1a19 commit f8ccc9d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ func addTree(
c.FileInfo.Mode = d.Type() &^ umask
}

if tree.FileInfo != nil && tree.FileInfo.Mode != 0 && c.Type != TypeSymlink {
c.FileInfo.Mode = tree.FileInfo.Mode
}

all[c.Destination] = c.WithFileInfoDefaults(umask, mtime)

return nil
Expand Down
29 changes: 29 additions & 0 deletions files/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package files_test

import (
"fmt"
"io/fs"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -896,6 +897,34 @@ func TestTree(t *testing.T) {
}, withoutFileInfo(results))
}

func TestTreeMode(t *testing.T) {
results, err := files.PrepareForPackager(
files.Contents{
{
Source: filepath.Join("testdata", "tree"),
Destination: "/usr/share/foo",
Type: files.TypeTree,
FileInfo: &files.ContentFileInfo{
Mode: 0o777,
},
},
},
0,
"",
false,
mtime,
)
require.NoError(t, err)

for _, f := range results {
if f.Destination == "/usr/" || f.Destination == "/usr/share/" || f.Type == files.TypeSymlink {
require.NotEqual(t, fs.FileMode(0o777).String(), f.FileInfo.Mode.String(), f.Destination)
continue
}
require.Equal(t, fs.FileMode(0o777).String(), f.FileInfo.Mode.String(), "%s: %s", f.Destination, f.Type)
}
}

func withoutFileInfo(contents files.Contents) files.Contents {
filtered := make(files.Contents, 0, len(contents))

Expand Down

0 comments on commit f8ccc9d

Please sign in to comment.