/
compat.go
56 lines (45 loc) · 1.07 KB
/
compat.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
package builder
import (
"archive/tar"
"os"
"path"
"github.com/pkg/errors"
"github.com/buildpacks/pack/internal/archive"
"github.com/buildpacks/pack/internal/dist"
"github.com/buildpacks/pack/internal/style"
)
const (
compatLifecycleDir = "/lifecycle"
)
func (b *Builder) compatLayer(order dist.Order, dest string) (string, error) {
if b.lifecycle == nil {
return "", nil
}
compatTar := path.Join(dest, "compat.tar")
fh, err := os.Create(compatTar)
if err != nil {
return "", err
}
defer fh.Close()
tw := tar.NewWriter(fh)
defer tw.Close()
if err := compatLifecycle(tw); err != nil {
return "", err
}
return compatTar, nil
}
func compatLifecycle(tw *tar.Writer) error {
return addSymlink(tw, compatLifecycleDir, lifecycleDir)
}
func addSymlink(tw *tar.Writer, name, linkName string) error {
if err := tw.WriteHeader(&tar.Header{
Name: name,
Linkname: linkName,
Typeflag: tar.TypeSymlink,
Mode: 0644,
ModTime: archive.NormalizedDateTime,
}); err != nil {
return errors.Wrapf(err, "creating %s symlink", style.Symbol(name))
}
return nil
}