mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-01 04:40:38 +00:00
Reading control files from .deb & .dsc files.
This commit is contained in:
Vendored
+41
-1
@@ -2,14 +2,17 @@ package debian
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
|
"bufio"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mkrautz/goar"
|
"github.com/mkrautz/goar"
|
||||||
|
"github.com/smira/aptly/utils"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetControlFileFromDeb read control file from deb package
|
// GetControlFileFromDeb reads control file from deb package
|
||||||
func GetControlFileFromDeb(packageFile string) (Stanza, error) {
|
func GetControlFileFromDeb(packageFile string) (Stanza, error) {
|
||||||
file, err := os.Open(packageFile)
|
file, err := os.Open(packageFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -57,3 +60,40 @@ func GetControlFileFromDeb(packageFile string) (Stanza, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetControlFileFromDsc reads control file from dsc package
|
||||||
|
func GetControlFileFromDsc(dscFile string, verifier utils.Verifier) (Stanza, error) {
|
||||||
|
file, err := os.Open(dscFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
line, err := bufio.NewReader(file).ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
file.Seek(0, 0)
|
||||||
|
|
||||||
|
var text *os.File
|
||||||
|
|
||||||
|
if strings.Index(line, "BEGIN PGP SIGN") != -1 {
|
||||||
|
text, err = verifier.ExtractClearsigned(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer text.Close()
|
||||||
|
} else {
|
||||||
|
text = file
|
||||||
|
}
|
||||||
|
|
||||||
|
reader := NewControlFileReader(text)
|
||||||
|
stanza, err := reader.ReadStanza()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return stanza, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+25
-1
@@ -1,13 +1,14 @@
|
|||||||
package debian
|
package debian
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/smira/aptly/utils"
|
||||||
. "launchpad.net/gocheck"
|
. "launchpad.net/gocheck"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DebSuite struct {
|
type DebSuite struct {
|
||||||
debFile string
|
debFile, dscFile, dscFileNoSign string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Suite(&DebSuite{})
|
var _ = Suite(&DebSuite{})
|
||||||
@@ -15,6 +16,8 @@ var _ = Suite(&DebSuite{})
|
|||||||
func (s *DebSuite) SetUpSuite(c *C) {
|
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.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")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DebSuite) TestGetControlFileFromDeb(c *C) {
|
func (s *DebSuite) TestGetControlFileFromDeb(c *C) {
|
||||||
@@ -30,3 +33,24 @@ func (s *DebSuite) TestGetControlFileFromDeb(c *C) {
|
|||||||
c.Check(st["Version"], Equals, "1.49.0.1")
|
c.Check(st["Version"], Equals, "1.49.0.1")
|
||||||
c.Check(st["Package"], Equals, "libboost-program-options-dev")
|
c.Check(st["Package"], Equals, "libboost-program-options-dev")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DebSuite) TestGetControlFileFromDsc(c *C) {
|
||||||
|
verifier := &utils.GpgVerifier{}
|
||||||
|
|
||||||
|
_, err := GetControlFileFromDsc("/no/such/file", verifier)
|
||||||
|
c.Check(err, ErrorMatches, ".*no such file or directory")
|
||||||
|
|
||||||
|
_, __file__, _, _ := runtime.Caller(0)
|
||||||
|
_, err = GetControlFileFromDsc(__file__, verifier)
|
||||||
|
c.Check(err, ErrorMatches, "malformed stanza syntax")
|
||||||
|
|
||||||
|
st, err := GetControlFileFromDsc(s.dscFile, verifier)
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(st["Version"], Equals, "0.6.1-1.3")
|
||||||
|
c.Check(st["Source"], Equals, "pyspi")
|
||||||
|
|
||||||
|
st, err = GetControlFileFromDsc(s.dscFileNoSign, verifier)
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(st["Version"], Equals, "0.6.1-1.4")
|
||||||
|
c.Check(st["Source"], Equals, "pyspi")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user