/usr/share/gocode/src/pault.ag/go/debian/control/dsc.go is in golang-pault-go-debian-dev 0.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | /* {{{ Copyright (c) Paul R. Tagliamonte <paultag@debian.org>, 2015
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. }}} */
package control
import (
"bufio"
"os"
"path/filepath"
"pault.ag/go/debian/dependency"
"pault.ag/go/debian/version"
"pault.ag/go/topsort"
)
// {{{ MD5 DSCFileHash
type FileListDSCFileHash struct{ SHADebianFileHash }
func (c *FileListDSCFileHash) UnmarshalControl(data string) error {
return c.unmarshalControl("md5", data)
}
// }}}
// A DSC is the ecapsulation of a Debian .dsc control file. This contains
// information about the source package, and is general handy.
//
// The Debian source control file is generated by dpkg-source when it builds
// the source archive, from other files in the source package.
// When unpacking, it is checked against the files and directories in the
// other parts of the source package.
type DSC struct {
Paragraph
Filename string
Format string
Source string
Binaries []string `control:"Binary" delim:","`
Architectures []dependency.Arch `control:"Architecture"`
Version version.Version
Origin string
Maintainer string
Uploaders []string
Homepage string
StandardsVersion string `control:"Standards-Version"`
BuildDepends dependency.Dependency `control:"Build-Depends"`
ChecksumsSha1 []SHA1DebianFileHash `control:"Checksums-Sha1" delim:"\n" strip:"\n\r\t "`
ChecksumsSha256 []SHA256DebianFileHash `control:"Checksums-Sha256" delim:"\n" strip:"\n\r\t "`
Files []FileListDSCFileHash `control:"Files" delim:"\n" strip:"\n\r\t "`
/*
TODO:
Package-List
*/
}
// Given a bunch of DSC objects, sort the packages topologically by
// build order by looking at the relationship between the Build-Depends
// field.
func OrderDSCForBuild(dscs []DSC, arch dependency.Arch) ([]DSC, error) {
sourceMapping := map[string]string{}
network := topsort.NewNetwork()
ret := []DSC{}
/*
* - Create binary -> source mapping.
* - Error if two sources provide the same binary
* - Create a node for each source
* - Create an edge from the source -> source
* - return sorted list of dsc files
*/
for _, dsc := range dscs {
for _, binary := range dsc.Binaries {
sourceMapping[binary] = dsc.Source
}
network.AddNode(dsc.Source, dsc)
}
for _, dsc := range dscs {
concreteBuildDepends := dsc.BuildDepends.GetPossibilities(arch)
for _, relation := range concreteBuildDepends {
if val, ok := sourceMapping[relation.Name]; ok {
err := network.AddEdge(val, dsc.Source)
if err != nil {
return nil, err
}
}
}
}
nodes, err := network.Sort()
if err != nil {
return nil, err
}
for _, node := range nodes {
ret = append(ret, node.Value.(DSC))
}
return ret, nil
}
// Given a path on the filesystem, Parse the file off the disk and return
// a pointer to a brand new DSC struct, unless error is set to a value
// other than nil.
func ParseDscFile(path string) (ret *DSC, err error) {
path, err = filepath.Abs(path)
if err != nil {
return nil, err
}
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
ret, err = ParseDsc(bufio.NewReader(f), path)
if err != nil {
return nil, err
}
return ret, nil
}
// Given a bufio.Reader, consume the Reader, and return a DSC object
// for use.
func ParseDsc(reader *bufio.Reader, path string) (*DSC, error) {
ret := DSC{Filename: path}
err := Unmarshal(&ret, reader)
if err != nil {
return nil, err
}
return &ret, nil
}
// Check to see if this .dsc contains any arch:all binary packages along
// with any arch dependent packages.
func (d *DSC) HasArchAll() bool {
for _, arch := range d.Architectures {
if arch.CPU == "all" && arch.OS == "all" && arch.ABI == "all" {
return true
}
}
return false
}
// Return a list of all entities that are responsible for the package's
// well being. The 0th element is always the package's Maintainer,
// with any Uploaders following.
func (d *DSC) Maintainers() []string {
return append([]string{d.Maintainer}, d.Uploaders...)
}
// Validate the attached files by checking the target Filesize and Checksum.
func (d DSC) Validate() error {
dscDir := filepath.Dir(d.Filename)
for _, f := range d.ChecksumsSha1 {
f.Filename = filepath.Join(dscDir, f.Filename)
if err := f.Validate(); err != nil {
return err
}
}
for _, f := range d.ChecksumsSha256 {
f.Filename = filepath.Join(dscDir, f.Filename)
if err := f.Validate(); err != nil {
return err
}
}
for _, f := range d.Files {
f.Filename = filepath.Join(dscDir, f.Filename)
if err := f.Validate(); err != nil {
return err
}
}
// TODO also verify that all three lists contain the _same_ files (and the same filesizes)
return nil
}
// vim: foldmethod=marker
|