예제 #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
}
예제 #2
0
// writeLayer is the re-exec entry point for writing a layer from a tar file
func writeLayer() {
	home := os.Args[1]
	id := os.Args[2]
	parentLayerPaths := os.Args[3:]

	err := func() error {
		err := winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege, winio.SeRestorePrivilege})
		if err != nil {
			return err
		}

		info := hcsshim.DriverInfo{
			Flavour: filterDriver,
			HomeDir: home,
		}

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

		size, err := writeLayerFromTar(os.Stdin, w)
		if err != nil {
			return err
		}

		err = w.Close()
		if err != nil {
			return err
		}

		fmt.Fprint(os.Stdout, size)
		return nil
	}()

	if err != nil {
		fmt.Fprint(os.Stderr, err)
		os.Exit(1)
	}
}
예제 #3
0
파일: windows.go 프로젝트: harche/docker
// writeLayer writes a layer from a tar file.
func writeLayer(layerData io.Reader, home string, id string, parentLayerPaths ...string) (int64, error) {
	err := winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege, winio.SeRestorePrivilege})
	if err != nil {
		return 0, err
	}
	if noreexec {
		defer func() {
			if err := winio.DisableProcessPrivileges([]string{winio.SeBackupPrivilege, winio.SeRestorePrivilege}); err != nil {
				// This should never happen, but just in case when in debugging mode.
				// See https://github.com/docker/docker/pull/28002#discussion_r86259241 for rationale.
				panic("Failed to disabled process privileges while in non re-exec mode")
			}
		}()
	}

	info := hcsshim.DriverInfo{
		Flavour: filterDriver,
		HomeDir: home,
	}

	w, err := hcsshim.NewLayerWriter(info, id, parentLayerPaths)
	if err != nil {
		return 0, err
	}

	size, err := writeLayerFromTar(layerData, w, filepath.Join(home, id))
	if err != nil {
		return 0, err
	}

	err = w.Close()
	if err != nil {
		return 0, err
	}

	return size, nil
}
예제 #4
0
파일: windows.go 프로젝트: contiv/docker
// 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
}