github.com/rawahars/moby@v24.0.4+incompatible/pkg/chrootarchive/diff_unix.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package chrootarchive // import "github.com/docker/docker/pkg/chrootarchive" 5 6 import ( 7 "io" 8 "path/filepath" 9 10 "github.com/containerd/containerd/pkg/userns" 11 "github.com/docker/docker/pkg/archive" 12 "golang.org/x/sys/unix" 13 ) 14 15 // applyLayerHandler parses a diff in the standard layer format from `layer`, and 16 // applies it to the directory `dest`. Returns the size in bytes of the 17 // contents of the layer. 18 func applyLayerHandler(dest string, layer io.Reader, options *archive.TarOptions, decompress bool) (size int64, err error) { 19 dest = filepath.Clean(dest) 20 if decompress { 21 decompressed, err := archive.DecompressStream(layer) 22 if err != nil { 23 return 0, err 24 } 25 defer decompressed.Close() 26 27 layer = decompressed 28 } 29 if options == nil { 30 options = &archive.TarOptions{} 31 } 32 if userns.RunningInUserNS() { 33 options.InUserNS = true 34 } 35 if options.ExcludePatterns == nil { 36 options.ExcludePatterns = []string{} 37 } 38 39 type result struct { 40 layerSize int64 41 err error 42 } 43 44 done := make(chan result) 45 err = goInChroot(dest, func() { 46 // We need to be able to set any perms 47 _ = unix.Umask(0) 48 49 size, err := archive.UnpackLayer("/", layer, options) 50 done <- result{layerSize: size, err: err} 51 }) 52 if err != nil { 53 return 0, err 54 } 55 res := <-done 56 return res.layerSize, res.err 57 }