diff_unix.go 966 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //go:build !windows
  2. package chrootarchive // import "github.com/docker/docker/pkg/chrootarchive"
  3. import (
  4. "io"
  5. "path/filepath"
  6. "github.com/containerd/containerd/pkg/userns"
  7. "github.com/docker/docker/pkg/archive"
  8. )
  9. // applyLayerHandler parses a diff in the standard layer format from `layer`, and
  10. // applies it to the directory `dest`. Returns the size in bytes of the
  11. // contents of the layer.
  12. func applyLayerHandler(dest string, layer io.Reader, options *archive.TarOptions, decompress bool) (size int64, err error) {
  13. dest = filepath.Clean(dest)
  14. if decompress {
  15. decompressed, err := archive.DecompressStream(layer)
  16. if err != nil {
  17. return 0, err
  18. }
  19. defer decompressed.Close()
  20. layer = decompressed
  21. }
  22. if options == nil {
  23. options = &archive.TarOptions{}
  24. }
  25. if userns.RunningInUserNS() {
  26. options.InUserNS = true
  27. }
  28. if options.ExcludePatterns == nil {
  29. options.ExcludePatterns = []string{}
  30. }
  31. return doUnpackLayer(dest, layer, options)
  32. }