-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.go
78 lines (74 loc) · 2.37 KB
/
package.go
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
package debanator
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"fmt"
"io"
"strings"
"pault.ag/go/debian/control"
"pault.ag/go/debian/deb"
"pault.ag/go/debian/dependency"
"pault.ag/go/debian/version"
)
// A group of debs of a package for different arches/version
type LogicalPackage struct {
Name string
// arch:version:package
Arches map[dependency.Arch]map[version.Version]control.BinaryIndex
}
func BinaryIndexFromDeb(r ReaderAtCloser, filePath string) (*control.BinaryIndex, error) {
debFile, err := deb.Load(r, "fakepath")
if err != nil {
return nil, fmt.Errorf("read deb: %w", err)
}
md5sum := md5.New()
sha1sum := sha1.New()
sha256sum := sha256.New()
hashWriter := io.MultiWriter(md5sum, sha1sum, sha256sum)
size, err := io.Copy(hashWriter, r)
if err != nil {
return nil, fmt.Errorf("hash file: %w", err)
}
bi := control.BinaryIndex{
Paragraph: control.Paragraph{
Values: make(map[string]string),
},
Package: debFile.Control.Package,
Source: debFile.Control.Source,
Version: debFile.Control.Version,
InstalledSize: debFile.Control.InstalledSize,
Size: int(size),
Maintainer: debFile.Control.Maintainer,
Architecture: debFile.Control.Architecture,
MultiArch: debFile.Control.MultiArch,
Description: debFile.Control.Description,
Homepage: debFile.Control.Homepage,
Section: debFile.Control.Section,
// FIXME: gross, make this more centrally managed somehow
Filename: strings.TrimPrefix(filePath, "/"),
Priority: debFile.Control.Priority,
MD5sum: fmt.Sprintf("%x", md5sum.Sum(nil)),
SHA1: fmt.Sprintf("%x", sha1sum.Sum(nil)),
SHA256: fmt.Sprintf("%x", sha256sum.Sum(nil)),
}
if debFile.Control.Depends.String() != "" {
bi.Paragraph.Set("Depends", debFile.Control.Depends.String())
}
if debFile.Control.Recommends.String() != "" {
bi.Paragraph.Set("Recommends", debFile.Control.Recommends.String())
}
if debFile.Control.Suggests.String() != "" {
bi.Paragraph.Set("Suggests", debFile.Control.Suggests.String())
}
if debFile.Control.Breaks.String() != "" {
bi.Paragraph.Set("Breaks", debFile.Control.Breaks.String())
}
if debFile.Control.Replaces.String() != "" {
bi.Paragraph.Set("Replaces", debFile.Control.Replaces.String())
}
if debFile.Control.BuiltUsing.String() != "" {
bi.Paragraph.Set("BuiltUsing", debFile.Control.BuiltUsing.String())
}
return &bi, nil
}