...

Source file src/github.com/Microsoft/hcsshim/computestorage/import.go

Documentation: github.com/Microsoft/hcsshim/computestorage

     1  //go:build windows
     2  
     3  package computestorage
     4  
     5  import (
     6  	"context"
     7  	"encoding/json"
     8  
     9  	"github.com/Microsoft/hcsshim/internal/oc"
    10  	"github.com/pkg/errors"
    11  	"go.opencensus.io/trace"
    12  )
    13  
    14  // ImportLayer imports a container layer.
    15  //
    16  // `layerPath` is a path to a directory to import the layer to. If the directory
    17  // does not exist it will be automatically created.
    18  //
    19  // `sourceFolderpath` is a pre-existing folder that contains the layer to
    20  // import.
    21  //
    22  // `layerData` is the parent layer data.
    23  func ImportLayer(ctx context.Context, layerPath, sourceFolderPath string, layerData LayerData) (err error) {
    24  	title := "hcsshim::ImportLayer"
    25  	ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
    26  	defer span.End()
    27  	defer func() { oc.SetSpanStatus(span, err) }()
    28  	span.AddAttributes(
    29  		trace.StringAttribute("layerPath", layerPath),
    30  		trace.StringAttribute("sourceFolderPath", sourceFolderPath),
    31  	)
    32  
    33  	bytes, err := json.Marshal(layerData)
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	err = hcsImportLayer(layerPath, sourceFolderPath, string(bytes))
    39  	if err != nil {
    40  		return errors.Wrap(err, "failed to import layer")
    41  	}
    42  	return nil
    43  }
    44  

View as plain text