-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive_linux.go
53 lines (44 loc) · 1.25 KB
/
archive_linux.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
package chrootarchive // import "github.com/docker/docker/pkg/chrootarchive"
import (
"io"
"github.com/docker/docker/pkg/archive"
"github.com/pkg/errors"
"golang.org/x/sys/unix"
)
func doUnpack(decompressedArchive io.Reader, relDest, root string, options *archive.TarOptions) error {
done := make(chan error)
err := goInChroot(root, func() { done <- archive.Unpack(decompressedArchive, relDest, options) })
if err != nil {
return err
}
return <-done
}
func doPack(relSrc, root string, options *archive.TarOptions) (io.ReadCloser, error) {
tb, err := archive.NewTarballer(relSrc, options)
if err != nil {
return nil, errors.Wrap(err, "error processing tar file")
}
err = goInChroot(root, tb.Do)
if err != nil {
return nil, errors.Wrap(err, "could not chroot")
}
return tb.Reader(), nil
}
func doUnpackLayer(root string, layer io.Reader, options *archive.TarOptions) (int64, error) {
type result struct {
layerSize int64
err error
}
done := make(chan result)
err := goInChroot(root, func() {
// We need to be able to set any perms
_ = unix.Umask(0)
size, err := archive.UnpackLayer("/", layer, options)
done <- result{layerSize: size, err: err}
})
if err != nil {
return 0, err
}
res := <-done
return res.layerSize, res.err
}