github.com/darciopacifico/docker@v1.9.0-rc1/pkg/chrootarchive/diff_windows.go (about)

     1  package chrootarchive
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"os"
     7  	"path/filepath"
     8  
     9  	"github.com/docker/docker/pkg/archive"
    10  	"github.com/docker/docker/pkg/longpath"
    11  )
    12  
    13  // applyLayerHandler parses a diff in the standard layer format from `layer`, and
    14  // applies it to the directory `dest`. Returns the size in bytes of the
    15  // contents of the layer.
    16  func applyLayerHandler(dest string, layer archive.Reader, options *archive.TarOptions, decompress bool) (size int64, err error) {
    17  	dest = filepath.Clean(dest)
    18  
    19  	// Ensure it is a Windows-style volume path
    20  	dest = longpath.AddPrefix(dest)
    21  
    22  	if decompress {
    23  		decompressed, err := archive.DecompressStream(layer)
    24  		if err != nil {
    25  			return 0, err
    26  		}
    27  		defer decompressed.Close()
    28  
    29  		layer = decompressed
    30  	}
    31  
    32  	tmpDir, err := ioutil.TempDir(os.Getenv("temp"), "temp-docker-extract")
    33  	if err != nil {
    34  		return 0, fmt.Errorf("ApplyLayer failed to create temp-docker-extract under %s. %s", dest, err)
    35  	}
    36  
    37  	s, err := archive.UnpackLayer(dest, layer, nil)
    38  	os.RemoveAll(tmpDir)
    39  	if err != nil {
    40  		return 0, fmt.Errorf("ApplyLayer %s failed UnpackLayer to %s", err, dest)
    41  	}
    42  
    43  	return s, nil
    44  }