Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: file mode when type: tree #779

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading