forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.go
74 lines (61 loc) · 1.67 KB
/
release.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
package release
import (
boshsys "github.com/cloudfoundry/bosh-agent/system"
bireljob "github.com/cloudfoundry/bosh-init/release/job"
birelpkg "github.com/cloudfoundry/bosh-init/release/pkg"
)
type release struct {
name string
version string
jobs []bireljob.Job
packages []*birelpkg.Package
extractedPath string
fs boshsys.FileSystem
}
type Release interface {
Name() string
Version() string
Jobs() []bireljob.Job
Packages() []*birelpkg.Package
FindJobByName(jobName string) (job bireljob.Job, found bool)
Delete() error
Exists() bool
}
func NewRelease(
name string,
version string,
jobs []bireljob.Job,
packages []*birelpkg.Package,
extractedPath string,
fs boshsys.FileSystem,
) Release {
return &release{
name: name,
version: version,
jobs: jobs,
packages: packages,
extractedPath: extractedPath,
fs: fs,
}
}
func (r *release) Name() string { return r.name }
func (r *release) Version() string { return r.version }
func (r *release) Jobs() []bireljob.Job { return r.jobs }
func (r *release) Packages() []*birelpkg.Package { return r.packages }
func (r *release) FindJobByName(jobName string) (bireljob.Job, bool) {
for _, job := range r.jobs {
if job.Name == jobName {
return job, true
}
}
return bireljob.Job{}, false
}
// Delete removes the extracted release code.
// Since packages and jobs are under the same path, they will be deleted too.
func (r *release) Delete() error {
return r.fs.RemoveAll(r.extractedPath)
}
// Exists returns false after Delete (or if extractedPath does not exist)
func (r *release) Exists() bool {
return r.fs.FileExists(r.extractedPath)
}