X Tutup
Skip to content

Commit bbe46b8

Browse files
jonyhy96zouyee
andcommitted
feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io> Co-authored-by: zounengren <zouyee1989@gmail.com>
1 parent 3ccd43c commit bbe46b8

File tree

299 files changed

+1896
-1874
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

299 files changed

+1896
-1874
lines changed

archive/tar.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package archive
1919
import (
2020
"archive/tar"
2121
"context"
22+
"errors"
23+
"fmt"
2224
"io"
2325
"os"
2426
"path/filepath"
@@ -30,7 +32,6 @@ import (
3032

3133
"github.com/containerd/containerd/log"
3234
"github.com/containerd/continuity/fs"
33-
"github.com/pkg/errors"
3435
)
3536

3637
var bufPool = &sync.Pool{
@@ -76,7 +77,7 @@ func WriteDiff(ctx context.Context, w io.Writer, a, b string, opts ...WriteDiffO
7677
var options WriteDiffOptions
7778
for _, opt := range opts {
7879
if err := opt(&options); err != nil {
79-
return errors.Wrap(err, "failed to apply option")
80+
return fmt.Errorf("failed to apply option: %w", err)
8081
}
8182
}
8283
if options.writeDiffFunc == nil {
@@ -97,7 +98,7 @@ func writeDiffNaive(ctx context.Context, w io.Writer, a, b string, _ WriteDiffOp
9798
cw := NewChangeWriter(w, b)
9899
err := fs.Changes(ctx, a, b, cw.HandleChange)
99100
if err != nil {
100-
return errors.Wrap(err, "failed to create diff tar stream")
101+
return fmt.Errorf("failed to create diff tar stream: %w", err)
101102
}
102103
return cw.Close()
103104
}
@@ -128,7 +129,7 @@ func Apply(ctx context.Context, root string, r io.Reader, opts ...ApplyOpt) (int
128129
var options ApplyOptions
129130
for _, opt := range opts {
130131
if err := opt(&options); err != nil {
131-
return 0, errors.Wrap(err, "failed to apply option")
132+
return 0, fmt.Errorf("failed to apply option: %w", err)
132133
}
133134
}
134135
if options.Filter == nil {
@@ -236,7 +237,7 @@ func applyNaive(ctx context.Context, root string, r io.Reader, options ApplyOpti
236237
ppath, base := filepath.Split(hdr.Name)
237238
ppath, err = fs.RootPath(root, ppath)
238239
if err != nil {
239-
return 0, errors.Wrap(err, "failed to get root path")
240+
return 0, fmt.Errorf("failed to get root path: %w", err)
240241
}
241242

242243
// Join to root before joining to parent path to ensure relative links are
@@ -266,7 +267,7 @@ func applyNaive(ctx context.Context, root string, r io.Reader, options ApplyOpti
266267
}
267268
writeFile, err := convertWhiteout(hdr, path)
268269
if err != nil {
269-
return 0, errors.Wrapf(err, "failed to convert whiteout file %q", hdr.Name)
270+
return 0, fmt.Errorf("failed to convert whiteout file %q: %w", hdr.Name, err)
270271
}
271272
if !writeFile {
272273
continue
@@ -373,7 +374,7 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header
373374
return nil
374375

375376
default:
376-
return errors.Errorf("unhandled tar header type %d\n", hdr.Typeflag)
377+
return fmt.Errorf("unhandled tar header type %d", hdr.Typeflag)
377378
}
378379

379380
// Lchown is not supported on Windows.
@@ -520,7 +521,7 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
520521
return err
521522
}
522523
if err := cw.tw.WriteHeader(hdr); err != nil {
523-
return errors.Wrap(err, "failed to write whiteout header")
524+
return fmt.Errorf("failed to write whiteout header: %w", err)
524525
}
525526
} else {
526527
var (
@@ -555,12 +556,12 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
555556
if strings.HasPrefix(name, string(filepath.Separator)) {
556557
name, err = filepath.Rel(string(filepath.Separator), name)
557558
if err != nil {
558-
return errors.Wrap(err, "failed to make path relative")
559+
return fmt.Errorf("failed to make path relative: %w", err)
559560
}
560561
}
561562
name, err = tarName(name)
562563
if err != nil {
563-
return errors.Wrap(err, "cannot canonicalize path")
564+
return fmt.Errorf("cannot canonicalize path: %w", err)
564565
}
565566
// suffix with '/' for directories
566567
if f.IsDir() && !strings.HasSuffix(name, "/") {
@@ -569,7 +570,7 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
569570
hdr.Name = name
570571

571572
if err := setHeaderForSpecialDevice(hdr, name, f); err != nil {
572-
return errors.Wrap(err, "failed to set device headers")
573+
return fmt.Errorf("failed to set device headers: %w", err)
573574
}
574575

575576
// additionalLinks stores file names which must be linked to
@@ -597,7 +598,7 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
597598
}
598599

599600
if capability, err := getxattr(source, "security.capability"); err != nil {
600-
return errors.Wrap(err, "failed to get capabilities xattr")
601+
return fmt.Errorf("failed to get capabilities xattr: %w", err)
601602
} else if len(capability) > 0 {
602603
if hdr.PAXRecords == nil {
603604
hdr.PAXRecords = map[string]string{}
@@ -609,19 +610,19 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
609610
return err
610611
}
611612
if err := cw.tw.WriteHeader(hdr); err != nil {
612-
return errors.Wrap(err, "failed to write file header")
613+
return fmt.Errorf("failed to write file header: %w", err)
613614
}
614615

615616
if hdr.Typeflag == tar.TypeReg && hdr.Size > 0 {
616617
file, err := open(source)
617618
if err != nil {
618-
return errors.Wrapf(err, "failed to open path: %v", source)
619+
return fmt.Errorf("failed to open path: %v: %w", source, err)
619620
}
620621
defer file.Close()
621622

622623
n, err := copyBuffered(context.TODO(), cw.tw, file)
623624
if err != nil {
624-
return errors.Wrap(err, "failed to copy")
625+
return fmt.Errorf("failed to copy: %w", err)
625626
}
626627
if n != hdr.Size {
627628
return errors.New("short write copying file")
@@ -640,7 +641,7 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
640641
return err
641642
}
642643
if err := cw.tw.WriteHeader(hdr); err != nil {
643-
return errors.Wrap(err, "failed to write file header")
644+
return fmt.Errorf("failed to write file header: %w", err)
644645
}
645646
}
646647
}
@@ -651,7 +652,7 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
651652
// Close closes this writer.
652653
func (cw *ChangeWriter) Close() error {
653654
if err := cw.tw.Close(); err != nil {
654-
return errors.Wrap(err, "failed to close tar writer")
655+
return fmt.Errorf("failed to close tar writer: %w", err)
655656
}
656657
return nil
657658
}
@@ -764,7 +765,7 @@ func validateWhiteout(path string) error {
764765
dir += string(filepath.Separator)
765766
}
766767
if !strings.HasPrefix(originalPath, dir) {
767-
return errors.Wrapf(errInvalidArchive, "invalid whiteout name: %v", base)
768+
return fmt.Errorf("invalid whiteout name: %v: %w", base, errInvalidArchive)
768769
}
769770
}
770771
return nil

archive/tar_linux_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/containerd/containerd/snapshots/overlay/overlayutils"
3232
"github.com/containerd/continuity/fs"
3333
"github.com/containerd/continuity/fs/fstest"
34-
"github.com/pkg/errors"
3534
)
3635

3736
func TestOverlayApply(t *testing.T) {
@@ -72,7 +71,7 @@ func TestOverlayApplyNoParents(t *testing.T) {
7271
cw.addedDirs = nil
7372
err := fs.Changes(ctx, a, b, cw.HandleChange)
7473
if err != nil {
75-
return errors.Wrap(err, "failed to create diff tar stream")
74+
return fmt.Errorf("failed to create diff tar stream: %w", err)
7675
}
7776
return cw.Close()
7877
},
@@ -97,7 +96,7 @@ type contextKey struct{}
9796
func (d overlayDiffApplier) TestContext(ctx context.Context) (context.Context, func(), error) {
9897
merged, err := os.MkdirTemp(d.tmp, "merged")
9998
if err != nil {
100-
return ctx, nil, errors.Wrap(err, "failed to make merged dir")
99+
return ctx, nil, fmt.Errorf("failed to make merged dir: %w", err)
101100
}
102101

103102
oc := &overlayContext{
@@ -118,7 +117,7 @@ func (d overlayDiffApplier) Apply(ctx context.Context, a fstest.Applier) (string
118117

119118
applyCopy, err := os.MkdirTemp(d.tmp, "apply-copy-")
120119
if err != nil {
121-
return "", nil, errors.Wrap(err, "failed to create temp dir")
120+
return "", nil, fmt.Errorf("failed to create temp dir: %w", err)
122121
}
123122
defer os.RemoveAll(applyCopy)
124123

@@ -128,33 +127,33 @@ func (d overlayDiffApplier) Apply(ctx context.Context, a fstest.Applier) (string
128127
}
129128

130129
if err = fs.CopyDir(applyCopy, base); err != nil {
131-
return "", nil, errors.Wrap(err, "failed to copy base")
130+
return "", nil, fmt.Errorf("failed to copy base: %w", err)
132131
}
133132

134133
if err := a.Apply(applyCopy); err != nil {
135-
return "", nil, errors.Wrap(err, "failed to apply changes to copy of base")
134+
return "", nil, fmt.Errorf("failed to apply changes to copy of base: %w", err)
136135
}
137136

138137
buf := bytes.NewBuffer(nil)
139138

140139
if err := d.diff(ctx, buf, base, applyCopy); err != nil {
141-
return "", nil, errors.Wrap(err, "failed to create diff")
140+
return "", nil, fmt.Errorf("failed to create diff: %w", err)
142141
}
143142

144143
if oc.mounted {
145144
if err := mount.Unmount(oc.merged, 0); err != nil {
146-
return "", nil, errors.Wrap(err, "failed to unmount")
145+
return "", nil, fmt.Errorf("failed to unmount: %w", err)
147146
}
148147
oc.mounted = false
149148
}
150149

151150
next, err := os.MkdirTemp(d.tmp, "lower-")
152151
if err != nil {
153-
return "", nil, errors.Wrap(err, "failed to create temp dir")
152+
return "", nil, fmt.Errorf("failed to create temp dir: %w", err)
154153
}
155154

156155
if _, err = Apply(ctx, next, buf, WithConvertWhiteout(OverlayConvertWhiteout), WithParents(oc.lowers)); err != nil {
157-
return "", nil, errors.Wrap(err, "failed to apply tar stream")
156+
return "", nil, fmt.Errorf("failed to apply tar stream: %w", err)
158157
}
159158

160159
oc.lowers = append([]string{next}, oc.lowers...)
@@ -172,7 +171,7 @@ func (d overlayDiffApplier) Apply(ctx context.Context, a fstest.Applier) (string
172171
}
173172

174173
if err := m.Mount(oc.merged); err != nil {
175-
return "", nil, errors.Wrapf(err, "failed to mount: %v", m)
174+
return "", nil, fmt.Errorf("failed to mount: %v: %w", m, err)
176175
}
177176
oc.mounted = true
178177

0 commit comments

Comments
 (0)
X Tutup