github.com/rentongzhang/docker@v1.8.2-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 ) 11 12 // ApplyLayer parses a diff in the standard layer format from `layer`, and 13 // applies it to the directory `dest`. Returns the size in bytes of the 14 // contents of the layer. 15 func ApplyLayer(dest string, layer archive.ArchiveReader) (size int64, err error) { 16 dest = filepath.Clean(dest) 17 decompressed, err := archive.DecompressStream(layer) 18 if err != nil { 19 return 0, err 20 } 21 defer decompressed.Close() 22 23 tmpDir, err := ioutil.TempDir(os.Getenv("temp"), "temp-docker-extract") 24 if err != nil { 25 return 0, fmt.Errorf("ApplyLayer failed to create temp-docker-extract under %s. %s", dest, err) 26 } 27 28 s, err := archive.UnpackLayer(dest, decompressed) 29 os.RemoveAll(tmpDir) 30 if err != nil { 31 return 0, fmt.Errorf("ApplyLayer %s failed UnpackLayer to %s", err, dest) 32 } 33 34 return s, nil 35 }