Example #1
0
// importLayer adds a new layer to the tag and graph store based on the given data.
func (d *Driver) importLayer(id string, layerData archive.Reader, parentLayerPaths []string) (size int64, err error) {
	var w hcsshim.LayerWriter
	w, err = hcsshim.NewLayerWriter(d.info, id, parentLayerPaths)
	if err != nil {
		return
	}
	size, err = writeLayerFromTar(layerData, w)
	if err != nil {
		w.Close()
		return
	}
	err = w.Close()
	if err != nil {
		return
	}
	return
}
Example #2
0
// importLayer adds a new layer to the tag and graph store based on the given data.
func (d *Driver) importLayer(id string, layerData archive.Reader, parentLayerPaths []string) (size int64, err error) {
	if hcsshim.IsTP4() {
		// Import from TP4 format to maintain compatibility with existing images.
		var tempFolder string
		tempFolder, err = ioutil.TempDir("", "hcs")
		if err != nil {
			return
		}
		defer os.RemoveAll(tempFolder)

		if size, err = chrootarchive.ApplyLayer(tempFolder, layerData); err != nil {
			return
		}
		if err = hcsshim.ImportLayer(d.info, id, tempFolder, parentLayerPaths); err != nil {
			return
		}
		return
	}

	var w hcsshim.LayerWriter
	w, err = hcsshim.NewLayerWriter(d.info, id, parentLayerPaths)
	if err != nil {
		return
	}

	size, err = writeLayerFromTar(layerData, w)
	if err != nil {
		w.Close()
		return
	}
	err = w.Close()
	if err != nil {
		return
	}
	return
}