import.go 1.1 KB

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