forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.go
108 lines (81 loc) · 2.85 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
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
package pkg
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
"github.com/cloudfoundry/bosh-cli/crypto"
. "github.com/cloudfoundry/bosh-cli/release/resource"
crypto2 "github.com/cloudfoundry/bosh-utils/crypto"
)
type ByName []*Package
func (a ByName) Len() int { return len(a) }
func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByName) Less(i, j int) bool { return a[i].Name() < a[j].Name() }
type Package struct {
resource Resource
Dependencies []*Package
dependencyNames []string
extractedPath string
fs boshsys.FileSystem
}
func NewPackage(resource Resource, dependencyNames []string) *Package {
return &Package{
resource: resource,
Dependencies: []*Package{},
dependencyNames: dependencyNames,
}
}
func NewExtractedPackage(resource Resource, dependencyNames []string, extractedPath string, fs boshsys.FileSystem) *Package {
return &Package{
resource: resource,
Dependencies: []*Package{},
dependencyNames: dependencyNames,
extractedPath: extractedPath,
fs: fs,
}
}
func (p Package) String() string { return p.Name() }
func (p Package) Name() string { return p.resource.Name() }
func (p Package) Fingerprint() string { return p.resource.Fingerprint() }
func (p *Package) ArchivePath() string { return p.resource.ArchivePath() }
func (p *Package) ArchiveDigest() string { return p.resource.ArchiveDigest() }
func (p *Package) RehashWithCalculator(calculator crypto.DigestCalculator, archiveFileReader crypto2.ArchiveDigestFilePathReader) (*Package, error) {
newResource, err := p.resource.RehashWithCalculator(calculator, archiveFileReader)
newPkg := *p
newPkg.resource = newResource
return &newPkg, err
}
func (p *Package) Build(dev, final ArchiveIndex) error { return p.resource.Build(dev, final) }
func (p *Package) Finalize(final ArchiveIndex) error { return p.resource.Finalize(final) }
func (p *Package) AttachDependencies(packages []*Package) error {
for _, pkgName := range p.dependencyNames {
var found bool
for _, pkg := range packages {
if pkg.Name() == pkgName {
p.Dependencies = append(p.Dependencies, pkg)
found = true
break
}
}
if !found {
errMsg := "Expected to find package '%s' since it's a dependency of package '%s'"
return bosherr.Errorf(errMsg, pkgName, p.Name())
}
}
return nil
}
func (p *Package) DependencyNames() []string { return p.dependencyNames }
func (p *Package) Deps() []Compilable {
var coms []Compilable
for _, dep := range p.Dependencies {
coms = append(coms, dep)
}
return coms
}
func (p *Package) IsCompiled() bool { return false }
func (p *Package) ExtractedPath() string { return p.extractedPath }
func (p *Package) CleanUp() error {
if p.fs != nil && len(p.extractedPath) > 0 {
return p.fs.RemoveAll(p.extractedPath)
}
return nil
}