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:
@@ -19,6 +19,8 @@ package archive
|
||||
import (
|
||||
"archive/tar"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -30,7 +32,6 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/continuity/fs"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var bufPool = &sync.Pool{
|
||||
@@ -76,7 +77,7 @@ func WriteDiff(ctx context.Context, w io.Writer, a, b string, opts ...WriteDiffO
|
||||
var options WriteDiffOptions
|
||||
for _, opt := range opts {
|
||||
if err := opt(&options); err != nil {
|
||||
return errors.Wrap(err, "failed to apply option")
|
||||
return fmt.Errorf("failed to apply option: %w", err)
|
||||
}
|
||||
}
|
||||
if options.writeDiffFunc == nil {
|
||||
@@ -97,7 +98,7 @@ func writeDiffNaive(ctx context.Context, w io.Writer, a, b string, _ WriteDiffOp
|
||||
cw := NewChangeWriter(w, b)
|
||||
err := fs.Changes(ctx, a, b, cw.HandleChange)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create diff tar stream")
|
||||
return fmt.Errorf("failed to create diff tar stream: %w", err)
|
||||
}
|
||||
return cw.Close()
|
||||
}
|
||||
@@ -128,7 +129,7 @@ func Apply(ctx context.Context, root string, r io.Reader, opts ...ApplyOpt) (int
|
||||
var options ApplyOptions
|
||||
for _, opt := range opts {
|
||||
if err := opt(&options); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to apply option")
|
||||
return 0, fmt.Errorf("failed to apply option: %w", err)
|
||||
}
|
||||
}
|
||||
if options.Filter == nil {
|
||||
@@ -236,7 +237,7 @@ func applyNaive(ctx context.Context, root string, r io.Reader, options ApplyOpti
|
||||
ppath, base := filepath.Split(hdr.Name)
|
||||
ppath, err = fs.RootPath(root, ppath)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to get root path")
|
||||
return 0, fmt.Errorf("failed to get root path: %w", err)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
writeFile, err := convertWhiteout(hdr, path)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to convert whiteout file %q", hdr.Name)
|
||||
return 0, fmt.Errorf("failed to convert whiteout file %q: %w", hdr.Name, err)
|
||||
}
|
||||
if !writeFile {
|
||||
continue
|
||||
@@ -373,7 +374,7 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header
|
||||
return nil
|
||||
|
||||
default:
|
||||
return errors.Errorf("unhandled tar header type %d\n", hdr.Typeflag)
|
||||
return fmt.Errorf("unhandled tar header type %d", hdr.Typeflag)
|
||||
}
|
||||
|
||||
// Lchown is not supported on Windows.
|
||||
@@ -520,7 +521,7 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
|
||||
return err
|
||||
}
|
||||
if err := cw.tw.WriteHeader(hdr); err != nil {
|
||||
return errors.Wrap(err, "failed to write whiteout header")
|
||||
return fmt.Errorf("failed to write whiteout header: %w", err)
|
||||
}
|
||||
} else {
|
||||
var (
|
||||
@@ -555,12 +556,12 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
|
||||
if strings.HasPrefix(name, string(filepath.Separator)) {
|
||||
name, err = filepath.Rel(string(filepath.Separator), name)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to make path relative")
|
||||
return fmt.Errorf("failed to make path relative: %w", err)
|
||||
}
|
||||
}
|
||||
name, err = tarName(name)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cannot canonicalize path")
|
||||
return fmt.Errorf("cannot canonicalize path: %w", err)
|
||||
}
|
||||
// suffix with '/' for directories
|
||||
if f.IsDir() && !strings.HasSuffix(name, "/") {
|
||||
@@ -569,7 +570,7 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
|
||||
hdr.Name = name
|
||||
|
||||
if err := setHeaderForSpecialDevice(hdr, name, f); err != nil {
|
||||
return errors.Wrap(err, "failed to set device headers")
|
||||
return fmt.Errorf("failed to set device headers: %w", err)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
if capability, err := getxattr(source, "security.capability"); err != nil {
|
||||
return errors.Wrap(err, "failed to get capabilities xattr")
|
||||
return fmt.Errorf("failed to get capabilities xattr: %w", err)
|
||||
} else if len(capability) > 0 {
|
||||
if hdr.PAXRecords == nil {
|
||||
hdr.PAXRecords = map[string]string{}
|
||||
@@ -609,19 +610,19 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
|
||||
return err
|
||||
}
|
||||
if err := cw.tw.WriteHeader(hdr); err != nil {
|
||||
return errors.Wrap(err, "failed to write file header")
|
||||
return fmt.Errorf("failed to write file header: %w", err)
|
||||
}
|
||||
|
||||
if hdr.Typeflag == tar.TypeReg && hdr.Size > 0 {
|
||||
file, err := open(source)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to open path: %v", source)
|
||||
return fmt.Errorf("failed to open path: %v: %w", source, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
n, err := copyBuffered(context.TODO(), cw.tw, file)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to copy")
|
||||
return fmt.Errorf("failed to copy: %w", err)
|
||||
}
|
||||
if n != hdr.Size {
|
||||
return errors.New("short write copying file")
|
||||
@@ -640,7 +641,7 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
|
||||
return err
|
||||
}
|
||||
if err := cw.tw.WriteHeader(hdr); err != nil {
|
||||
return errors.Wrap(err, "failed to write file header")
|
||||
return fmt.Errorf("failed to write file header: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -651,7 +652,7 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
|
||||
// Close closes this writer.
|
||||
func (cw *ChangeWriter) Close() error {
|
||||
if err := cw.tw.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close tar writer")
|
||||
return fmt.Errorf("failed to close tar writer: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -764,7 +765,7 @@ func validateWhiteout(path string) error {
|
||||
dir += string(filepath.Separator)
|
||||
}
|
||||
if !strings.HasPrefix(originalPath, dir) {
|
||||
return errors.Wrapf(errInvalidArchive, "invalid whiteout name: %v", base)
|
||||
return fmt.Errorf("invalid whiteout name: %v: %w", base, errInvalidArchive)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -31,7 +31,6 @@ import (
|
||||
"github.com/containerd/containerd/snapshots/overlay/overlayutils"
|
||||
"github.com/containerd/continuity/fs"
|
||||
"github.com/containerd/continuity/fs/fstest"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func TestOverlayApply(t *testing.T) {
|
||||
@@ -72,7 +71,7 @@ func TestOverlayApplyNoParents(t *testing.T) {
|
||||
cw.addedDirs = nil
|
||||
err := fs.Changes(ctx, a, b, cw.HandleChange)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create diff tar stream")
|
||||
return fmt.Errorf("failed to create diff tar stream: %w", err)
|
||||
}
|
||||
return cw.Close()
|
||||
},
|
||||
@@ -97,7 +96,7 @@ type contextKey struct{}
|
||||
func (d overlayDiffApplier) TestContext(ctx context.Context) (context.Context, func(), error) {
|
||||
merged, err := os.MkdirTemp(d.tmp, "merged")
|
||||
if err != nil {
|
||||
return ctx, nil, errors.Wrap(err, "failed to make merged dir")
|
||||
return ctx, nil, fmt.Errorf("failed to make merged dir: %w", err)
|
||||
}
|
||||
|
||||
oc := &overlayContext{
|
||||
@@ -118,7 +117,7 @@ func (d overlayDiffApplier) Apply(ctx context.Context, a fstest.Applier) (string
|
||||
|
||||
applyCopy, err := os.MkdirTemp(d.tmp, "apply-copy-")
|
||||
if err != nil {
|
||||
return "", nil, errors.Wrap(err, "failed to create temp dir")
|
||||
return "", nil, fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(applyCopy)
|
||||
|
||||
@@ -128,33 +127,33 @@ func (d overlayDiffApplier) Apply(ctx context.Context, a fstest.Applier) (string
|
||||
}
|
||||
|
||||
if err = fs.CopyDir(applyCopy, base); err != nil {
|
||||
return "", nil, errors.Wrap(err, "failed to copy base")
|
||||
return "", nil, fmt.Errorf("failed to copy base: %w", err)
|
||||
}
|
||||
|
||||
if err := a.Apply(applyCopy); err != nil {
|
||||
return "", nil, errors.Wrap(err, "failed to apply changes to copy of base")
|
||||
return "", nil, fmt.Errorf("failed to apply changes to copy of base: %w", err)
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
|
||||
if err := d.diff(ctx, buf, base, applyCopy); err != nil {
|
||||
return "", nil, errors.Wrap(err, "failed to create diff")
|
||||
return "", nil, fmt.Errorf("failed to create diff: %w", err)
|
||||
}
|
||||
|
||||
if oc.mounted {
|
||||
if err := mount.Unmount(oc.merged, 0); err != nil {
|
||||
return "", nil, errors.Wrap(err, "failed to unmount")
|
||||
return "", nil, fmt.Errorf("failed to unmount: %w", err)
|
||||
}
|
||||
oc.mounted = false
|
||||
}
|
||||
|
||||
next, err := os.MkdirTemp(d.tmp, "lower-")
|
||||
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 = Apply(ctx, next, buf, WithConvertWhiteout(OverlayConvertWhiteout), WithParents(oc.lowers)); err != nil {
|
||||
return "", nil, errors.Wrap(err, "failed to apply tar stream")
|
||||
return "", nil, fmt.Errorf("failed to apply tar stream: %w", err)
|
||||
}
|
||||
|
||||
oc.lowers = append([]string{next}, oc.lowers...)
|
||||
@@ -172,7 +171,7 @@ func (d overlayDiffApplier) Apply(ctx context.Context, a fstest.Applier) (string
|
||||
}
|
||||
|
||||
if err := m.Mount(oc.merged); err != nil {
|
||||
return "", nil, errors.Wrapf(err, "failed to mount: %v", m)
|
||||
return "", nil, fmt.Errorf("failed to mount: %v: %w", m, err)
|
||||
}
|
||||
oc.mounted = true
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -36,7 +37,6 @@ import (
|
||||
"github.com/containerd/containerd/pkg/testutil"
|
||||
"github.com/containerd/continuity/fs"
|
||||
"github.com/containerd/continuity/fs/fstest"
|
||||
"github.com/pkg/errors"
|
||||
exec "golang.org/x/sys/execabs"
|
||||
)
|
||||
|
||||
@@ -235,10 +235,10 @@ func TestBreakouts(t *testing.T) {
|
||||
unbrokenCheck := func(root string) error {
|
||||
b, err := os.ReadFile(filepath.Join(root, "etc", "unbroken"))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read unbroken")
|
||||
return fmt.Errorf("failed to read unbroken: %w", err)
|
||||
}
|
||||
if string(b) != expected {
|
||||
return errors.Errorf("/etc/unbroken: unexpected value %s, expected %s", b, expected)
|
||||
return fmt.Errorf("/etc/unbroken: unexpected value %s, expected %s", b, expected)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -257,7 +257,7 @@ func TestBreakouts(t *testing.T) {
|
||||
}
|
||||
|
||||
if got := fi.Mode() & os.ModeSymlink; got != os.ModeSymlink {
|
||||
return errors.Errorf("%s should be symlink", fi.Name())
|
||||
return fmt.Errorf("%s should be symlink", fi.Name())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -285,7 +285,7 @@ func TestBreakouts(t *testing.T) {
|
||||
}
|
||||
|
||||
if t1 != t2 {
|
||||
return errors.Wrapf(errFileDiff, "%#v and %#v", t1, t2)
|
||||
return fmt.Errorf("%#v and %#v: %w", t1, t2, errFileDiff)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -310,7 +310,7 @@ func TestBreakouts(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
if !os.SameFile(s1, s2) {
|
||||
return errors.Wrapf(errFileDiff, "%#v and %#v", s1, s2)
|
||||
return fmt.Errorf("%#v and %#v: %w", s1, s2, errFileDiff)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -335,7 +335,7 @@ func TestBreakouts(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
if !bytes.Equal(b, content) {
|
||||
return errors.Errorf("content differs: expected %v, got %v", content, b)
|
||||
return fmt.Errorf("content differs: expected %v, got %v", content, b)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -422,7 +422,7 @@ func TestBreakouts(t *testing.T) {
|
||||
validator: func(root string) error {
|
||||
b, err := os.ReadFile(filepath.Join(root, "etc", "emptied"))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read unbroken")
|
||||
return fmt.Errorf("failed to read unbroken: %w", err)
|
||||
}
|
||||
if len(b) > 0 {
|
||||
return errors.New("/etc/emptied: non-empty")
|
||||
@@ -774,7 +774,7 @@ func TestBreakouts(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
if perm := fi.Mode() & os.ModePerm; perm != 0400 {
|
||||
return errors.Errorf("%s perm changed from 0400 to %04o", p, perm)
|
||||
return fmt.Errorf("%s perm changed from 0400 to %04o", p, perm)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
@@ -800,7 +800,7 @@ func TestApplyTar(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
if _, err := os.Stat(p); err != nil {
|
||||
return errors.Wrapf(err, "failure checking existence for %v", d)
|
||||
return fmt.Errorf("failure checking existence for %v: %w", d, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -844,23 +844,23 @@ func TestApplyTar(t *testing.T) {
|
||||
func testApply(a fstest.Applier) error {
|
||||
td, err := os.MkdirTemp("", "test-apply-")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp dir")
|
||||
return fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(td)
|
||||
dest, err := os.MkdirTemp("", "test-apply-dest-")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp dir")
|
||||
return fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(dest)
|
||||
|
||||
if err := a.Apply(td); err != nil {
|
||||
return errors.Wrap(err, "failed to apply filesystem changes")
|
||||
return fmt.Errorf("failed to apply filesystem changes: %w", err)
|
||||
}
|
||||
|
||||
tarArgs := []string{"c", "-C", td}
|
||||
names, err := readDirNames(td)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read directory names")
|
||||
return fmt.Errorf("failed to read directory names: %w", err)
|
||||
}
|
||||
tarArgs = append(tarArgs, names...)
|
||||
|
||||
@@ -868,15 +868,15 @@ func testApply(a fstest.Applier) error {
|
||||
|
||||
arch, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create stdout pipe")
|
||||
return fmt.Errorf("failed to create stdout pipe: %w", err)
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return errors.Wrap(err, "failed to start command")
|
||||
return fmt.Errorf("failed to start command: %w", err)
|
||||
}
|
||||
|
||||
if _, err := Apply(context.Background(), dest, arch); err != nil {
|
||||
return errors.Wrap(err, "failed to apply tar stream")
|
||||
return fmt.Errorf("failed to apply tar stream: %w", err)
|
||||
}
|
||||
|
||||
return fstest.CheckDirectoryEqual(td, dest)
|
||||
@@ -885,17 +885,17 @@ func testApply(a fstest.Applier) error {
|
||||
func testBaseDiff(a fstest.Applier) error {
|
||||
td, err := os.MkdirTemp("", "test-base-diff-")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp dir")
|
||||
return fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(td)
|
||||
dest, err := os.MkdirTemp("", "test-base-diff-dest-")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp dir")
|
||||
return fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(dest)
|
||||
|
||||
if err := a.Apply(td); err != nil {
|
||||
return errors.Wrap(err, "failed to apply filesystem changes")
|
||||
return fmt.Errorf("failed to apply filesystem changes: %w", err)
|
||||
}
|
||||
|
||||
arch := Diff(context.Background(), "", td)
|
||||
@@ -903,7 +903,7 @@ func testBaseDiff(a fstest.Applier) error {
|
||||
cmd := exec.Command(tarCmd, "x", "-C", dest)
|
||||
cmd.Stdin = arch
|
||||
if err := cmd.Run(); err != nil {
|
||||
return errors.Wrap(err, "tar command failed")
|
||||
return fmt.Errorf("tar command failed: %w", err)
|
||||
}
|
||||
|
||||
return fstest.CheckDirectoryEqual(td, dest)
|
||||
@@ -912,18 +912,18 @@ func testBaseDiff(a fstest.Applier) error {
|
||||
func testDiffApply(appliers ...fstest.Applier) error {
|
||||
td, err := os.MkdirTemp("", "test-diff-apply-")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp dir")
|
||||
return fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(td)
|
||||
dest, err := os.MkdirTemp("", "test-diff-apply-dest-")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp dir")
|
||||
return fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(dest)
|
||||
|
||||
for _, a := range appliers {
|
||||
if err := a.Apply(td); err != nil {
|
||||
return errors.Wrap(err, "failed to apply filesystem changes")
|
||||
return fmt.Errorf("failed to apply filesystem changes: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -931,18 +931,18 @@ func testDiffApply(appliers ...fstest.Applier) error {
|
||||
if len(appliers) > 1 {
|
||||
for _, a := range appliers[:len(appliers)-1] {
|
||||
if err := a.Apply(dest); err != nil {
|
||||
return errors.Wrap(err, "failed to apply base filesystem changes")
|
||||
return fmt.Errorf("failed to apply base filesystem changes: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
diffBytes, err := io.ReadAll(Diff(context.Background(), dest, td))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create diff")
|
||||
return fmt.Errorf("failed to create diff: %w", err)
|
||||
}
|
||||
|
||||
if _, err := Apply(context.Background(), dest, bytes.NewReader(diffBytes)); err != nil {
|
||||
return errors.Wrap(err, "failed to apply tar stream")
|
||||
return fmt.Errorf("failed to apply tar stream: %w", err)
|
||||
}
|
||||
|
||||
return fstest.CheckDirectoryEqual(td, dest)
|
||||
@@ -1194,10 +1194,10 @@ func dirEntry(name string, mode int) tarEntryValidator {
|
||||
return errors.New("not directory type")
|
||||
}
|
||||
if hdr.Name != name {
|
||||
return errors.Errorf("wrong name %q, expected %q", hdr.Name, name)
|
||||
return fmt.Errorf("wrong name %q, expected %q", hdr.Name, name)
|
||||
}
|
||||
if hdr.Mode != int64(mode) {
|
||||
return errors.Errorf("wrong mode %o, expected %o", hdr.Mode, mode)
|
||||
return fmt.Errorf("wrong mode %o, expected %o", hdr.Mode, mode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1209,10 +1209,10 @@ func fileEntry(name string, expected []byte, mode int) tarEntryValidator {
|
||||
return errors.New("not file type")
|
||||
}
|
||||
if hdr.Name != name {
|
||||
return errors.Errorf("wrong name %q, expected %q", hdr.Name, name)
|
||||
return fmt.Errorf("wrong name %q, expected %q", hdr.Name, name)
|
||||
}
|
||||
if hdr.Mode != int64(mode) {
|
||||
return errors.Errorf("wrong mode %o, expected %o", hdr.Mode, mode)
|
||||
return fmt.Errorf("wrong mode %o, expected %o", hdr.Mode, mode)
|
||||
}
|
||||
if !bytes.Equal(b, expected) {
|
||||
return errors.New("different file content")
|
||||
@@ -1227,10 +1227,10 @@ func linkEntry(name, link string) tarEntryValidator {
|
||||
return errors.New("not link type")
|
||||
}
|
||||
if hdr.Name != name {
|
||||
return errors.Errorf("wrong name %q, expected %q", hdr.Name, name)
|
||||
return fmt.Errorf("wrong name %q, expected %q", hdr.Name, name)
|
||||
}
|
||||
if hdr.Linkname != link {
|
||||
return errors.Errorf("wrong link %q, expected %q", hdr.Linkname, link)
|
||||
return fmt.Errorf("wrong link %q, expected %q", hdr.Linkname, link)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1243,10 +1243,10 @@ func whiteoutEntry(name string) tarEntryValidator {
|
||||
|
||||
return func(hdr *tar.Header, b []byte) error {
|
||||
if hdr.Typeflag != tar.TypeReg {
|
||||
return errors.Errorf("not file type: %q", hdr.Typeflag)
|
||||
return fmt.Errorf("not file type: %q", hdr.Typeflag)
|
||||
}
|
||||
if hdr.Name != whiteOut {
|
||||
return errors.Errorf("wrong name %q, expected whiteout %q", hdr.Name, name)
|
||||
return fmt.Errorf("wrong name %q, expected whiteout %q", hdr.Name, name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1309,7 +1309,7 @@ type diffApplier struct{}
|
||||
func (d diffApplier) TestContext(ctx context.Context) (context.Context, func(), error) {
|
||||
base, err := os.MkdirTemp("", "test-diff-apply-")
|
||||
if err != nil {
|
||||
return ctx, nil, errors.Wrap(err, "failed to create temp dir")
|
||||
return ctx, nil, fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
return context.WithValue(ctx, d, base), func() {
|
||||
os.RemoveAll(base)
|
||||
@@ -1321,23 +1321,23 @@ func (d diffApplier) Apply(ctx context.Context, a fstest.Applier) (string, func(
|
||||
|
||||
applyCopy, err := os.MkdirTemp("", "test-diffapply-apply-copy-")
|
||||
if err != nil {
|
||||
return "", nil, errors.Wrap(err, "failed to create temp dir")
|
||||
return "", nil, fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(applyCopy)
|
||||
if err = fs.CopyDir(applyCopy, base); err != nil {
|
||||
return "", nil, errors.Wrap(err, "failed to copy base")
|
||||
return "", nil, fmt.Errorf("failed to copy base: %w", err)
|
||||
}
|
||||
if err := a.Apply(applyCopy); err != nil {
|
||||
return "", nil, errors.Wrap(err, "failed to apply changes to copy of base")
|
||||
return "", nil, fmt.Errorf("failed to apply changes to copy of base: %w", err)
|
||||
}
|
||||
|
||||
diffBytes, err := io.ReadAll(Diff(ctx, base, applyCopy))
|
||||
if err != nil {
|
||||
return "", nil, errors.Wrap(err, "failed to create diff")
|
||||
return "", nil, fmt.Errorf("failed to create diff: %w", err)
|
||||
}
|
||||
|
||||
if _, err = Apply(ctx, base, bytes.NewReader(diffBytes)); err != nil {
|
||||
return "", nil, errors.Wrap(err, "failed to apply tar stream")
|
||||
return "", nil, fmt.Errorf("failed to apply tar stream: %w", err)
|
||||
}
|
||||
|
||||
return base, nil, nil
|
||||
|
||||
@@ -21,6 +21,8 @@ package archive
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
@@ -29,7 +31,6 @@ import (
|
||||
"github.com/containerd/containerd/pkg/userns"
|
||||
"github.com/containerd/continuity/fs"
|
||||
"github.com/containerd/continuity/sysx"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
@@ -139,7 +140,7 @@ func getxattr(path, attr string) ([]byte, error) {
|
||||
func setxattr(path, key, value string) error {
|
||||
// Do not set trusted attributes
|
||||
if strings.HasPrefix(key, "trusted.") {
|
||||
return errors.Wrap(unix.ENOTSUP, "admin attributes from archive not supported")
|
||||
return fmt.Errorf("admin attributes from archive not supported: %w", unix.ENOTSUP)
|
||||
}
|
||||
return unix.Lsetxattr(path, key, []byte(value), 0)
|
||||
}
|
||||
@@ -159,12 +160,12 @@ func copyDirInfo(fi os.FileInfo, path string) error {
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to chown %s", path)
|
||||
return fmt.Errorf("failed to chown %s: %w", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.Chmod(path, fi.Mode()); err != nil {
|
||||
return errors.Wrapf(err, "failed to chmod %s", path)
|
||||
return fmt.Errorf("failed to chmod %s: %w", path, err)
|
||||
}
|
||||
|
||||
timespec := []unix.Timespec{
|
||||
@@ -172,7 +173,7 @@ func copyDirInfo(fi os.FileInfo, path string) error {
|
||||
unix.NsecToTimespec(syscall.TimespecToNsec(fs.StatMtime(st))),
|
||||
}
|
||||
if err := unix.UtimesNanoAt(unix.AT_FDCWD, path, timespec, unix.AT_SYMLINK_NOFOLLOW); err != nil {
|
||||
return errors.Wrapf(err, "failed to utime %s", path)
|
||||
return fmt.Errorf("failed to utime %s: %w", path, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -184,7 +185,7 @@ func copyUpXAttrs(dst, src string) error {
|
||||
if err == unix.ENOTSUP || err == sysx.ENODATA {
|
||||
return nil
|
||||
}
|
||||
return errors.Wrapf(err, "failed to list xattrs on %s", src)
|
||||
return fmt.Errorf("failed to list xattrs on %s: %w", src, err)
|
||||
}
|
||||
for _, xattr := range xattrKeys {
|
||||
// Do not copy up trusted attributes
|
||||
@@ -196,10 +197,10 @@ func copyUpXAttrs(dst, src string) error {
|
||||
if err == unix.ENOTSUP || err == sysx.ENODATA {
|
||||
continue
|
||||
}
|
||||
return errors.Wrapf(err, "failed to get xattr %q on %s", xattr, src)
|
||||
return fmt.Errorf("failed to get xattr %q on %s: %w", xattr, src, err)
|
||||
}
|
||||
if err := lsetxattrCreate(dst, xattr, data); err != nil {
|
||||
return errors.Wrapf(err, "failed to set xattr %q on %s", xattr, dst)
|
||||
return fmt.Errorf("failed to set xattr %q on %s: %w", xattr, dst, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,12 @@ package archive
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/containerd/sys"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// tarName returns platform-specific filepath
|
||||
@@ -112,7 +112,7 @@ func setxattr(path, key, value string) error {
|
||||
|
||||
func copyDirInfo(fi os.FileInfo, path string) error {
|
||||
if err := os.Chmod(path, fi.Mode()); err != nil {
|
||||
return errors.Wrapf(err, "failed to chmod %s", path)
|
||||
return fmt.Errorf("failed to chmod %s: %w", path, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -20,11 +20,10 @@
|
||||
package archive
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func chtimes(path string, atime, mtime time.Time) error {
|
||||
@@ -33,7 +32,7 @@ func chtimes(path string, atime, mtime time.Time) error {
|
||||
utimes[1] = unix.NsecToTimespec(mtime.UnixNano())
|
||||
|
||||
if err := unix.UtimesNanoAt(unix.AT_FDCWD, path, utimes[0:], unix.AT_SYMLINK_NOFOLLOW); err != nil {
|
||||
return errors.Wrapf(err, "failed call to UtimesNanoAt for %s", path)
|
||||
return fmt.Errorf("failed call to UtimesNanoAt for %s: %w", path, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user