forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
86 lines (70 loc) · 2.66 KB
/
provider.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
package release
import (
gopath "path"
boshcmd "github.com/cloudfoundry/bosh-utils/fileutil"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
bicrypto "github.com/cloudfoundry/bosh-cli/crypto"
boshjob "github.com/cloudfoundry/bosh-cli/release/job"
boshlic "github.com/cloudfoundry/bosh-cli/release/license"
boshpkg "github.com/cloudfoundry/bosh-cli/release/pkg"
. "github.com/cloudfoundry/bosh-cli/release/resource"
)
type Provider struct {
fingerprinter Fingerprinter
cmdRunner boshsys.CmdRunner
compressor boshcmd.Compressor
sha1calc bicrypto.SHA1Calculator
fs boshsys.FileSystem
logger boshlog.Logger
}
func NewProvider(
cmdRunner boshsys.CmdRunner,
compressor boshcmd.Compressor,
sha1calc bicrypto.SHA1Calculator,
fs boshsys.FileSystem,
logger boshlog.Logger,
) Provider {
fingerprinter := NewFingerprinterImpl(sha1calc, fs)
return Provider{
fingerprinter: fingerprinter,
cmdRunner: cmdRunner,
compressor: compressor,
sha1calc: sha1calc,
fs: fs,
logger: logger,
}
}
func (p Provider) NewMultiReader(dirPath string) MultiReader {
opts := MultiReaderOpts{
ArchiveReader: p.NewArchiveReader(),
ManifestReader: p.NewManifestReader(),
DirReader: p.NewDirReader(dirPath),
}
return NewMultiReader(opts, p.fs)
}
func (p Provider) NewExtractingArchiveReader() ArchiveReader { return p.archiveReader(true) }
func (p Provider) NewArchiveReader() ArchiveReader { return p.archiveReader(false) }
func (p Provider) archiveReader(extracting bool) ArchiveReader {
jobReader := boshjob.NewArchiveReaderImpl(extracting, p.compressor, p.fs)
pkgReader := boshpkg.NewArchiveReaderImpl(extracting, p.compressor, p.fs)
return NewArchiveReader(jobReader, pkgReader, p.compressor, p.fs, p.logger)
}
func (p Provider) NewDirReader(dirPath string) DirReader {
archiveFactory := func(files []File, prepFiles []File, chunks []string) Archive {
return NewArchiveImpl(
files, prepFiles, chunks, dirPath, p.fingerprinter, p.compressor, p.sha1calc, p.cmdRunner, p.fs)
}
srcDirPath := gopath.Join(dirPath, "src")
blobsDirPath := gopath.Join(dirPath, "blobs")
jobDirReader := boshjob.NewDirReaderImpl(archiveFactory, p.fs)
pkgDirReader := boshpkg.NewDirReaderImpl(archiveFactory, srcDirPath, blobsDirPath, p.fs)
licDirReader := boshlic.NewDirReaderImpl(archiveFactory, p.fs)
return NewDirReader(jobDirReader, pkgDirReader, licDirReader, p.fs, p.logger)
}
func (p Provider) NewManifestReader() ManifestReader {
return NewManifestReader(p.fs, p.logger)
}
func (p Provider) NewArchiveWriter() ArchiveWriter {
return NewArchiveWriter(p.compressor, p.fs, p.logger)
}