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:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user