feat: replace github.com/pkg/errors to errors

Signed-off-by: haoyun <yun.hao@daocloud.io>
Co-authored-by: zounengren <zouyee1989@gmail.com>
This commit is contained in:
haoyun
2022-01-07 10:19:31 +08:00
parent 3ccd43c8f6
commit bbe46b8c43
299 changed files with 1896 additions and 1874 deletions

View File

@@ -18,12 +18,13 @@ package mount
import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/Microsoft/hcsshim"
"github.com/pkg/errors"
)
var (
@@ -34,7 +35,7 @@ var (
// Mount to the provided target
func (m *Mount) Mount(target string) error {
if m.Type != "windows-layer" {
return errors.Errorf("invalid windows mount type: '%s'", m.Type)
return fmt.Errorf("invalid windows mount type: '%s'", m.Type)
}
home, layerID := filepath.Split(m.Source)
@@ -49,22 +50,22 @@ func (m *Mount) Mount(target string) error {
}
if err = hcsshim.ActivateLayer(di, layerID); err != nil {
return errors.Wrapf(err, "failed to activate layer %s", m.Source)
return fmt.Errorf("failed to activate layer %s: %w", m.Source, err)
}
if err = hcsshim.PrepareLayer(di, layerID, parentLayerPaths); err != nil {
return errors.Wrapf(err, "failed to prepare layer %s", m.Source)
return fmt.Errorf("failed to prepare layer %s: %w", m.Source, err)
}
// We can link the layer mount path to the given target. It is an UNC path, and it needs
// a trailing backslash.
mountPath, err := hcsshim.GetLayerMountPath(di, layerID)
if err != nil {
return errors.Wrapf(err, "failed to get layer mount path for %s", m.Source)
return fmt.Errorf("failed to get layer mount path for %s: %w", m.Source, err)
}
mountPath = mountPath + `\`
if err = os.Symlink(mountPath, target); err != nil {
return errors.Wrapf(err, "failed to link mount to taget %s", target)
return fmt.Errorf("failed to link mount to taget %s: %w", target, err)
}
return nil
}
@@ -80,7 +81,7 @@ func (m *Mount) GetParentPaths() ([]string, error) {
if strings.HasPrefix(option, ParentLayerPathsFlag) {
err := json.Unmarshal([]byte(option[len(ParentLayerPathsFlag):]), &parentLayerPaths)
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal parent layer paths from mount")
return nil, fmt.Errorf("failed to unmarshal parent layer paths from mount: %w", err)
}
}
}
@@ -97,10 +98,10 @@ func Unmount(mount string, flags int) error {
)
if err := hcsshim.UnprepareLayer(di, layerID); err != nil {
return errors.Wrapf(err, "failed to unprepare layer %s", mount)
return fmt.Errorf("failed to unprepare layer %s: %w", mount, err)
}
if err := hcsshim.DeactivateLayer(di, layerID); err != nil {
return errors.Wrapf(err, "failed to deactivate layer %s", mount)
return fmt.Errorf("failed to deactivate layer %s: %w", mount, err)
}
return nil