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,6 +18,7 @@ package native
import (
"context"
"fmt"
"os"
"path/filepath"
@@ -27,7 +28,6 @@ import (
"github.com/containerd/containerd/snapshots/storage"
"github.com/containerd/continuity/fs"
"github.com/pkg/errors"
)
type snapshotter struct {
@@ -137,7 +137,7 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
s, err := storage.GetSnapshot(ctx, key)
t.Rollback()
if err != nil {
return nil, errors.Wrap(err, "failed to get snapshot mount")
return nil, fmt.Errorf("failed to get snapshot mount: %w", err)
}
return o.mounts(s), nil
}
@@ -162,7 +162,7 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
if rerr := t.Rollback(); rerr != nil {
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
}
return errors.Wrap(err, "failed to commit snapshot")
return fmt.Errorf("failed to commit snapshot: %w", err)
}
return t.Commit()
}
@@ -184,14 +184,14 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
id, _, err := storage.Remove(ctx, key)
if err != nil {
return errors.Wrap(err, "failed to remove")
return fmt.Errorf("failed to remove: %w", err)
}
path := o.getSnapshotDir(id)
renamed := filepath.Join(o.root, "snapshots", "rm-"+id)
if err := os.Rename(path, renamed); err != nil {
if !os.IsNotExist(err) {
return errors.Wrap(err, "failed to rename")
return fmt.Errorf("failed to rename: %w", err)
}
renamed = ""
}
@@ -205,7 +205,7 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
log.G(ctx).WithError(err1).WithField("path", renamed).Error("failed to rename after failed commit")
}
}
return errors.Wrap(err, "failed to commit")
return fmt.Errorf("failed to commit: %w", err)
}
if renamed != "" {
if err := os.RemoveAll(renamed); err != nil {
@@ -235,21 +235,21 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
if kind == snapshots.KindActive || parent == "" {
td, err = os.MkdirTemp(filepath.Join(o.root, "snapshots"), "new-")
if err != nil {
return nil, errors.Wrap(err, "failed to create temp dir")
return nil, fmt.Errorf("failed to create temp dir: %w", err)
}
if err := os.Chmod(td, 0755); err != nil {
return nil, errors.Wrapf(err, "failed to chmod %s to 0755", td)
return nil, fmt.Errorf("failed to chmod %s to 0755: %w", td, err)
}
defer func() {
if err != nil {
if td != "" {
if err1 := os.RemoveAll(td); err1 != nil {
err = errors.Wrapf(err, "remove failed: %v", err1)
err = fmt.Errorf("remove failed: %v: %w", err1, err)
}
}
if path != "" {
if err1 := os.RemoveAll(path); err1 != nil {
err = errors.Wrapf(err, "failed to remove path: %v", err1)
err = fmt.Errorf("failed to remove path: %v: %w", err1, err)
}
}
}
@@ -266,7 +266,7 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
if rerr := t.Rollback(); rerr != nil {
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
}
return nil, errors.Wrap(err, "failed to create snapshot")
return nil, fmt.Errorf("failed to create snapshot: %w", err)
}
if td != "" {
@@ -281,7 +281,7 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
fs.WithXAttrErrorHandler(xattrErrorHandler),
}
if err := fs.CopyDir(td, parent, copyDirOpts...); err != nil {
return nil, errors.Wrap(err, "copying of parent failed")
return nil, fmt.Errorf("copying of parent failed: %w", err)
}
}
@@ -290,13 +290,13 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
if rerr := t.Rollback(); rerr != nil {
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
}
return nil, errors.Wrap(err, "failed to rename")
return nil, fmt.Errorf("failed to rename: %w", err)
}
td = ""
}
if err := t.Commit(); err != nil {
return nil, errors.Wrap(err, "commit failed")
return nil, fmt.Errorf("commit failed: %w", err)
}
return o.mounts(s), nil