1
1
Fork 0
mirror of https://github.com/goreleaser/nfpm synced 2024-05-06 04:36:16 +02:00

fix: file mode when type: tree (#779)

closes #777

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2024-01-31 14:51:47 -03:00 committed by GitHub
parent 48d1a19eb6
commit f8ccc9df94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View File

@ -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

View File

@ -2,6 +2,7 @@ package files_test
import (
"fmt"
"io/fs"
"os"
"path/filepath"
"runtime"
@ -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))