...

Source file src/github.com/Microsoft/hcsshim/layer.go

Documentation: github.com/Microsoft/hcsshim

     1  //go:build windows
     2  
     3  package hcsshim
     4  
     5  import (
     6  	"context"
     7  	"crypto/sha1"
     8  	"path/filepath"
     9  
    10  	"github.com/Microsoft/go-winio/pkg/guid"
    11  	"github.com/Microsoft/hcsshim/internal/wclayer"
    12  )
    13  
    14  func layerPath(info *DriverInfo, id string) string {
    15  	return filepath.Join(info.HomeDir, id)
    16  }
    17  
    18  func ActivateLayer(info DriverInfo, id string) error {
    19  	return wclayer.ActivateLayer(context.Background(), layerPath(&info, id))
    20  }
    21  func CreateLayer(info DriverInfo, id, parent string) error {
    22  	return wclayer.CreateLayer(context.Background(), layerPath(&info, id), parent)
    23  }
    24  
    25  // New clients should use CreateScratchLayer instead. Kept in to preserve API compatibility.
    26  func CreateSandboxLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
    27  	return wclayer.CreateScratchLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
    28  }
    29  func CreateScratchLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
    30  	return wclayer.CreateScratchLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
    31  }
    32  func DeactivateLayer(info DriverInfo, id string) error {
    33  	return wclayer.DeactivateLayer(context.Background(), layerPath(&info, id))
    34  }
    35  func DestroyLayer(info DriverInfo, id string) error {
    36  	return wclayer.DestroyLayer(context.Background(), layerPath(&info, id))
    37  }
    38  
    39  // New clients should use ExpandScratchSize instead. Kept in to preserve API compatibility.
    40  func ExpandSandboxSize(info DriverInfo, layerId string, size uint64) error {
    41  	return wclayer.ExpandScratchSize(context.Background(), layerPath(&info, layerId), size)
    42  }
    43  func ExpandScratchSize(info DriverInfo, layerId string, size uint64) error {
    44  	return wclayer.ExpandScratchSize(context.Background(), layerPath(&info, layerId), size)
    45  }
    46  func ExportLayer(info DriverInfo, layerId string, exportFolderPath string, parentLayerPaths []string) error {
    47  	return wclayer.ExportLayer(context.Background(), layerPath(&info, layerId), exportFolderPath, parentLayerPaths)
    48  }
    49  func GetLayerMountPath(info DriverInfo, id string) (string, error) {
    50  	return wclayer.GetLayerMountPath(context.Background(), layerPath(&info, id))
    51  }
    52  func GetSharedBaseImages() (imageData string, err error) {
    53  	return wclayer.GetSharedBaseImages(context.Background())
    54  }
    55  func ImportLayer(info DriverInfo, layerID string, importFolderPath string, parentLayerPaths []string) error {
    56  	return wclayer.ImportLayer(context.Background(), layerPath(&info, layerID), importFolderPath, parentLayerPaths)
    57  }
    58  func LayerExists(info DriverInfo, id string) (bool, error) {
    59  	return wclayer.LayerExists(context.Background(), layerPath(&info, id))
    60  }
    61  func PrepareLayer(info DriverInfo, layerId string, parentLayerPaths []string) error {
    62  	return wclayer.PrepareLayer(context.Background(), layerPath(&info, layerId), parentLayerPaths)
    63  }
    64  func ProcessBaseLayer(path string) error {
    65  	return wclayer.ProcessBaseLayer(context.Background(), path)
    66  }
    67  func ProcessUtilityVMImage(path string) error {
    68  	return wclayer.ProcessUtilityVMImage(context.Background(), path)
    69  }
    70  func UnprepareLayer(info DriverInfo, layerId string) error {
    71  	return wclayer.UnprepareLayer(context.Background(), layerPath(&info, layerId))
    72  }
    73  func ConvertToBaseLayer(path string) error {
    74  	return wclayer.ConvertToBaseLayer(context.Background(), path)
    75  }
    76  
    77  type DriverInfo struct {
    78  	Flavour int
    79  	HomeDir string
    80  }
    81  
    82  type GUID [16]byte
    83  
    84  func NameToGuid(name string) (id GUID, err error) {
    85  	g, err := wclayer.NameToGuid(context.Background(), name)
    86  	return g.ToWindowsArray(), err
    87  }
    88  
    89  func NewGUID(source string) *GUID {
    90  	h := sha1.Sum([]byte(source))
    91  	var g GUID
    92  	copy(g[0:], h[0:16])
    93  	return &g
    94  }
    95  
    96  func (g *GUID) ToString() string {
    97  	return guid.FromWindowsArray(*g).String()
    98  }
    99  
   100  type LayerReader = wclayer.LayerReader
   101  
   102  func NewLayerReader(info DriverInfo, layerID string, parentLayerPaths []string) (LayerReader, error) {
   103  	return wclayer.NewLayerReader(context.Background(), layerPath(&info, layerID), parentLayerPaths)
   104  }
   105  
   106  type LayerWriter = wclayer.LayerWriter
   107  
   108  func NewLayerWriter(info DriverInfo, layerID string, parentLayerPaths []string) (LayerWriter, error) {
   109  	return wclayer.NewLayerWriter(context.Background(), layerPath(&info, layerID), parentLayerPaths)
   110  }
   111  
   112  type WC_LAYER_DESCRIPTOR = wclayer.WC_LAYER_DESCRIPTOR
   113  

View as plain text