-
Notifications
You must be signed in to change notification settings - Fork 162
/
archive_reader.go
52 lines (42 loc) · 1.31 KB
/
archive_reader.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
package pkg
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshcmd "github.com/cloudfoundry/bosh-utils/fileutil"
boshsys "github.com/cloudfoundry/bosh-utils/system"
boshman "github.com/cloudfoundry/bosh-cli/release/manifest"
. "github.com/cloudfoundry/bosh-cli/release/resource"
)
type ArchiveReaderImpl struct {
extract bool
compressor boshcmd.Compressor
fs boshsys.FileSystem
}
func NewArchiveReaderImpl(
extract bool,
compressor boshcmd.Compressor,
fs boshsys.FileSystem,
) ArchiveReaderImpl {
return ArchiveReaderImpl{
extract: extract,
compressor: compressor,
fs: fs,
}
}
func (r ArchiveReaderImpl) Read(ref boshman.PackageRef, path string) (*Package, error) {
resource := NewResourceWithBuiltArchive(ref.Name, ref.Fingerprint, path, ref.SHA1)
pkg := NewPackage(resource, ref.Dependencies)
if r.extract {
extractPath, err := r.fs.TempDir("bosh-release-pkg")
if err != nil {
return nil, bosherr.WrapErrorf(err, "Creating temp directory to extract package '%s'", path)
}
// Used for future clean up
pkg.extractedPath = extractPath
pkg.fs = r.fs
err = r.compressor.DecompressFileToDir(path, extractPath, boshcmd.CompressorOptions{})
if err != nil {
return nil, bosherr.WrapErrorf(err, "Extracting package '%s'", ref.Name)
}
}
return pkg, nil
}