layerexists.go 844 B

123456789101112131415161718192021222324252627282930
  1. //go:build windows
  2. package wclayer
  3. import (
  4. "context"
  5. "github.com/Microsoft/hcsshim/internal/hcserror"
  6. "github.com/Microsoft/hcsshim/internal/oc"
  7. "go.opencensus.io/trace"
  8. )
  9. // LayerExists will return true if a layer with the given id exists and is known
  10. // to the system.
  11. func LayerExists(ctx context.Context, path string) (_ bool, err error) {
  12. title := "hcsshim::LayerExists"
  13. ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
  14. defer span.End()
  15. defer func() { oc.SetSpanStatus(span, err) }()
  16. span.AddAttributes(trace.StringAttribute("path", path))
  17. // Call the procedure itself.
  18. var exists uint32
  19. err = layerExists(&stdDriverInfo, path, &exists)
  20. if err != nil {
  21. return false, hcserror.New(err, title, "")
  22. }
  23. span.AddAttributes(trace.BoolAttribute("layer-exists", exists != 0))
  24. return exists != 0, nil
  25. }