Skip to content

Commit

Permalink
extract: Proper modes with multiple copies
Browse files Browse the repository at this point in the history
We use the source tar entry header to compute fs.FileMode. When the
target path has a different mode, we modify the source header first.
Consequently, when a source path is mapped to multiple target paths, and
when one target path overrides the mode and the following one doesn't,
the following one will have the first one's mode. Fix it by remembering
the source header mode.
  • Loading branch information
woky committed Oct 9, 2023
1 parent bc77cf5 commit 1b67780
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/deb/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func extractData(dataReader io.Reader, options *ExtractOptions) error {
}

var pathReader io.Reader = tarReader
origMode := tarHeader.Mode
for _, extractInfo := range extractInfos {
if contentIsCached {
pathReader = bytes.NewReader(contentCache)
Expand All @@ -258,6 +259,7 @@ func extractData(dataReader io.Reader, options *ExtractOptions) error {
if err := createParents(targetPath); err != nil {
return err
}
tarHeader.Mode = origMode
if extractInfo.Mode != 0 {
tarHeader.Mode = int64(extractInfo.Mode)
}
Expand Down
26 changes: 26 additions & 0 deletions internal/deb/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,32 @@ var extractTests = []extractTest{{
"/a/b/c/": "dir 0706",
"/a/b/c/d": "file 0601 empty",
},
}, {
summary: "Copies with different permissions",
pkgdata: testutil.MustMakeDeb([]testutil.TarEntry{
Dir(0701, "./a/"),
Reg(0601, "./b", ""),
}),
options: deb.ExtractOptions{
Extract: map[string][]deb.ExtractInfo{
"/a/": []deb.ExtractInfo{
{Path: "/b/"},
{Path: "/c/", Mode: 0702},
{Path: "/d/", Mode: 01777},
{Path: "/e/"},
{Path: "/f/", Mode: 0723},
{Path: "/g/"},
},
},
},
result: map[string]string{
"/b/": "dir 0701",
"/c/": "dir 0702",
"/d/": "dir 01777",
"/e/": "dir 0701",
"/f/": "dir 0723",
"/g/": "dir 0701",
},
}}

func (s *S) TestExtract(c *C) {
Expand Down

0 comments on commit 1b67780

Please sign in to comment.