make deb reader handle new control.tar options introduced in dpkg 1.17.6

newly supported is uncompressed control.tar and xz compressed
control.tar.xz. latter is used by ubuntu for dbgsym ddebs.

Fixes #655
This commit is contained in:
Harald Sitter
2017-10-31 11:36:31 +01:00
parent 79d68ec3a7
commit 1885cbd6a2
3 changed files with 43 additions and 9 deletions
+33 -8
View File
@@ -37,21 +37,46 @@ func GetControlFileFromDeb(packageFile string) (Stanza, error) {
library := ar.NewReader(file) library := ar.NewReader(file)
for { for {
header, err := library.Next() header, err := library.Next()
if err == io.EOF { if err == io.EOF {
return nil, fmt.Errorf("unable to find control.tar.gz part in package %s", packageFile) return nil, fmt.Errorf("unable to find control.tar.* part in package %s", packageFile)
} }
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read .deb archive %s: %s", packageFile, err) return nil, fmt.Errorf("unable to read .deb archive %s: %s", packageFile, err)
} }
if header.Name == "control.tar.gz" { // As per deb(5) version 1.19.0.4 the control file may be:
ungzip, err := gzip.NewReader(library) // - control.tar (since 1.17.6)
if err != nil { // - control.tar.gz
return nil, fmt.Errorf("unable to ungzip control file from %s. Error: %s", packageFile, err) // - control.tar.xz (since 1.17.6)
} // Look for all of the above and uncompress as necessary.
defer ungzip.Close() if strings.HasPrefix(header.Name, "control.tar") {
bufReader := bufio.NewReader(library)
untar := tar.NewReader(ungzip) var tarInput io.Reader
switch header.Name {
case "control.tar":
tarInput = bufReader
case "control.tar.gz":
ungzip, err := gzip.NewReader(bufReader)
if err != nil {
return nil, errors.Wrapf(err, "unable to ungzip %s from %s", header.Name, packageFile)
}
defer ungzip.Close()
tarInput = ungzip
case "control.tar.xz":
unxz, err := xz.NewReader(bufReader)
if err != nil {
return nil, errors.Wrapf(err, "unable to unxz %s from %s", header.Name, packageFile)
}
defer unxz.Close()
tarInput = unxz
default:
return nil, fmt.Errorf("unsupported tar compression in %s: %s", packageFile, header.Name)
}
untar := tar.NewReader(tarInput)
for { for {
tarHeader, err := untar.Next() tarHeader, err := untar.Next()
if err == io.EOF { if err == io.EOF {
+10 -1
View File
@@ -11,7 +11,7 @@ import (
) )
type DebSuite struct { type DebSuite struct {
debFile, debFile2, dscFile, dscFileNoSign string debFile, debFile2, debFileWithXzControl, dscFile, dscFileNoSign string
} }
var _ = Suite(&DebSuite{}) var _ = Suite(&DebSuite{})
@@ -20,6 +20,7 @@ func (s *DebSuite) SetUpSuite(c *C) {
_, _File, _, _ := runtime.Caller(0) _, _File, _, _ := runtime.Caller(0)
s.debFile = filepath.Join(filepath.Dir(_File), "../system/files/libboost-program-options-dev_1.49.0.1_i386.deb") s.debFile = filepath.Join(filepath.Dir(_File), "../system/files/libboost-program-options-dev_1.49.0.1_i386.deb")
s.debFile2 = filepath.Join(filepath.Dir(_File), "../system/changes/hardlink_0.2.1_amd64.deb") s.debFile2 = filepath.Join(filepath.Dir(_File), "../system/changes/hardlink_0.2.1_amd64.deb")
s.debFileWithXzControl = filepath.Join(filepath.Dir(_File), "../system/changes/libqt5concurrent5-dbgsym_5.9.1+dfsg-2+18.04+bionic+build4_amd64.ddeb")
s.dscFile = filepath.Join(filepath.Dir(_File), "../system/files/pyspi_0.6.1-1.3.dsc") s.dscFile = filepath.Join(filepath.Dir(_File), "../system/files/pyspi_0.6.1-1.3.dsc")
s.dscFileNoSign = filepath.Join(filepath.Dir(_File), "../system/files/pyspi-0.6.1-1.3.stripped.dsc") s.dscFileNoSign = filepath.Join(filepath.Dir(_File), "../system/files/pyspi-0.6.1-1.3.stripped.dsc")
} }
@@ -38,6 +39,14 @@ func (s *DebSuite) TestGetControlFileFromDeb(c *C) {
c.Check(st["Package"], Equals, "libboost-program-options-dev") c.Check(st["Package"], Equals, "libboost-program-options-dev")
} }
func (s *DebSuite) TestGetControlFileFromDebWithXzControl(c *C) {
// Has control.tar.xz archive inside.
st, err := GetControlFileFromDeb(s.debFileWithXzControl)
c.Check(err, IsNil)
c.Check(st["Version"], Equals, "5.9.1+dfsg-2+18.04+bionic+build4")
c.Check(st["Package"], Equals, "libqt5concurrent5-dbgsym")
}
func (s *DebSuite) TestGetControlFileFromDsc(c *C) { func (s *DebSuite) TestGetControlFileFromDsc(c *C) {
verifier := &pgp.GoVerifier{} verifier := &pgp.GoVerifier{}