Skip to content
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
7 changes: 7 additions & 0 deletions pkg/apk/apk/installed.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ func (a *APK) updateScriptsTar(pkg *Package, controlTarGz io.Reader, sourceDateE
continue
}

// Ignore files that aren't executable.
// This is mostly to ignore .melange.yaml files in the control section,
// but apk itself has hardcoded list of scripts that we might want to do too.
if header.FileInfo().Mode().Perm()&0555 != 0555 {
Comment on lines +157 to +160
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not immediately obvious to me from this why we're checking for these exact perm bits (r+x for all 3) but maybe that's just because I don't know this part of the domain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I copied this from melange SCA that does similar checks for entirely different reasons, and it matched what I saw from sampling real-world scripts in alpine. If this ends up being brittle I'll come back and figure out exactly what apk does here and replicate it.

continue
}

origName := header.Name
header.Name = fmt.Sprintf("%s-%s.Q1%s%s", pkg.Name, pkg.Version, base64.StdEncoding.EncodeToString(pkg.Checksum), origName)

Expand Down
10 changes: 8 additions & 2 deletions pkg/apk/apk/installed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,25 @@ func TestUpdateScriptsTar(t *testing.T) {
".post-install": []byte("echo 'post install'"),
".pre-upgrade": []byte("echo 'pre upgrade'"),
".post-upgrade": []byte("echo 'post upgrade'"),
".PKGINFO": []byte(pkginfo),
}
var buf bytes.Buffer
gw := gzip.NewWriter(&buf)
tw := tar.NewWriter(gw)
for name, content := range scripts {
_ = tw.WriteHeader(&tar.Header{
Name: name,
Mode: 0o644,
Mode: 0o755,
Size: int64(len(content)),
})
_, _ = tw.Write(content)
}

_ = tw.WriteHeader(&tar.Header{
Name: ".PKGINFO",
Mode: 0o644,
Size: int64(len([]byte(pkginfo))),
})
_, _ = tw.Write([]byte(pkginfo))
tw.Close()
gw.Close()

Expand Down