layerexists.go 807 B

12345678910111213141516171819202122232425262728293031323334
  1. package wclayer
  2. import (
  3. "github.com/Microsoft/hcsshim/internal/hcserror"
  4. "github.com/sirupsen/logrus"
  5. )
  6. // LayerExists will return true if a layer with the given id exists and is known
  7. // to the system.
  8. func LayerExists(path string) (_ bool, err error) {
  9. title := "hcsshim::LayerExists"
  10. fields := logrus.Fields{
  11. "path": path,
  12. }
  13. logrus.WithFields(fields).Debug(title)
  14. defer func() {
  15. if err != nil {
  16. fields[logrus.ErrorKey] = err
  17. logrus.WithFields(fields).Error(err)
  18. } else {
  19. logrus.WithFields(fields).Debug(title + " - succeeded")
  20. }
  21. }()
  22. // Call the procedure itself.
  23. var exists uint32
  24. err = layerExists(&stdDriverInfo, path, &exists)
  25. if err != nil {
  26. return false, hcserror.New(err, title+" - failed", "")
  27. }
  28. fields["layer-exists"] = exists != 0
  29. return exists != 0, nil
  30. }