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,10 +18,10 @@ package mount
import (
"context"
"fmt"
"os"
"github.com/containerd/containerd/log"
"github.com/pkg/errors"
)
var tempMountLocation = getTempDir()
@@ -32,7 +32,7 @@ var tempMountLocation = getTempDir()
func WithTempMount(ctx context.Context, mounts []Mount, f func(root string) error) (err error) {
root, uerr := os.MkdirTemp(tempMountLocation, "containerd-mount")
if uerr != nil {
return errors.Wrapf(uerr, "failed to create temp dir")
return fmt.Errorf("failed to create temp dir: %w", err)
}
// We use Remove here instead of RemoveAll.
// The RemoveAll will delete the temp dir and all children it contains.
@@ -50,18 +50,21 @@ func WithTempMount(ctx context.Context, mounts []Mount, f func(root string) erro
// We should do defer first, if not we will not do Unmount when only a part of Mounts are failed.
defer func() {
if uerr = UnmountAll(root, 0); uerr != nil {
uerr = errors.Wrapf(uerr, "failed to unmount %s", root)
uerr = fmt.Errorf("failed to unmount %s: %w", root, uerr)
if err == nil {
err = uerr
} else {
err = errors.Wrap(err, uerr.Error())
err = fmt.Errorf("%s: %w", uerr.Error(), err)
}
}
}()
if uerr = All(mounts, root); uerr != nil {
return errors.Wrapf(uerr, "failed to mount %s", root)
return fmt.Errorf("failed to mount %s: %w", root, uerr)
}
return errors.Wrapf(f(root), "mount callback failed on %s", root)
if err := f(root); err != nil {
return fmt.Errorf("mount callback failed on %s: %w", root, err)
}
return nil
}
func getTempDir() string {