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