Skip to content

Commit

Permalink
replace pkg/errors
Browse files Browse the repository at this point in the history
Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
  • Loading branch information
zounengren committed Sep 22, 2021
1 parent 60d22e8 commit 8343682
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
10 changes: 5 additions & 5 deletions fifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ package fifo

import (
"context"
"fmt"
"io"
"os"
"runtime"
"sync"
"syscall"

"github.com/pkg/errors"
"golang.org/x/sys/unix"
)

Expand All @@ -48,12 +48,12 @@ var leakCheckWg *sync.WaitGroup
func OpenFifoDup2(ctx context.Context, fn string, flag int, perm os.FileMode, fd int) (io.ReadWriteCloser, error) {
f, err := openFifo(ctx, fn, flag, perm)
if err != nil {
return nil, errors.Wrap(err, "fifo error")
return nil, fmt.Errorf("fifo error: %w", err)
}

if err := unix.Dup2(int(f.file.Fd()), fd); err != nil {
_ = f.Close()
return nil, errors.Wrap(err, "dup2 error")
return nil, fmt.Errorf("dup2 error: %w", err)
}

return f, nil
Expand All @@ -77,7 +77,7 @@ func openFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (*fifo
if _, err := os.Stat(fn); err != nil {
if os.IsNotExist(err) && flag&syscall.O_CREAT != 0 {
if err := syscall.Mkfifo(fn, uint32(perm&os.ModePerm)); err != nil && !os.IsExist(err) {
return nil, errors.Wrapf(err, "error creating fifo %v", fn)
return nil, fmt.Errorf("error creating fifo %v: %w", fn, err)
}
} else {
return nil, err
Expand Down Expand Up @@ -138,7 +138,7 @@ func openFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (*fifo
case <-ctx.Done():
err = ctx.Err()
default:
err = errors.Errorf("fifo %v was closed before opening", h.Name())
err = fmt.Errorf("fifo %v was closed before opening", h.Name())
}
if file != nil {
file.Close()
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/containerd/fifo
go 1.13

require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.6.1
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
12 changes: 5 additions & 7 deletions handle_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"os"
"sync"
"syscall"

"github.com/pkg/errors"
)

//nolint:golint
Expand All @@ -42,7 +40,7 @@ type handle struct {
func getHandle(fn string) (*handle, error) {
f, err := os.OpenFile(fn, O_PATH, 0)
if err != nil {
return nil, errors.Wrapf(err, "failed to open %v with O_PATH", fn)
return nil, fmt.Errorf("failed to open %v with O_PATH: %w", fn, err)
}

var (
Expand All @@ -51,7 +49,7 @@ func getHandle(fn string) (*handle, error) {
)
if err := syscall.Fstat(int(fd), &stat); err != nil {
f.Close()
return nil, errors.Wrapf(err, "failed to stat handle %v", fd)
return nil, fmt.Errorf("failed to stat handle %v: %w", fd, err)
}

h := &handle{
Expand All @@ -66,7 +64,7 @@ func getHandle(fn string) (*handle, error) {
// check /proc just in case
if _, err := os.Stat(h.procPath()); err != nil {
f.Close()
return nil, errors.Wrapf(err, "couldn't stat %v", h.procPath())
return nil, fmt.Errorf("couldn't stat %v: %w", h.procPath(), err)
}

return h, nil
Expand All @@ -83,11 +81,11 @@ func (h *handle) Name() string {
func (h *handle) Path() (string, error) {
var stat syscall.Stat_t
if err := syscall.Stat(h.procPath(), &stat); err != nil {
return "", errors.Wrapf(err, "path %v could not be statted", h.procPath())
return "", fmt.Errorf("path %v could not be statted: %w", h.procPath(), err)
}
//nolint:unconvert
if uint64(stat.Dev) != h.dev || stat.Ino != h.ino {
return "", errors.Errorf("failed to verify handle %v/%v %v/%v", stat.Dev, h.dev, stat.Ino, h.ino)
return "", fmt.Errorf("failed to verify handle %v/%v %v/%v", stat.Dev, h.dev, stat.Ino, h.ino)
}
return h.procPath(), nil
}
Expand Down
9 changes: 4 additions & 5 deletions handle_nolinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
package fifo

import (
"fmt"
"syscall"

"github.com/pkg/errors"
)

type handle struct {
Expand All @@ -33,7 +32,7 @@ type handle struct {
func getHandle(fn string) (*handle, error) {
var stat syscall.Stat_t
if err := syscall.Stat(fn, &stat); err != nil {
return nil, errors.Wrapf(err, "failed to stat %v", fn)
return nil, fmt.Errorf("failed to stat %v: %w", fn, err)
}

h := &handle{
Expand All @@ -48,10 +47,10 @@ func getHandle(fn string) (*handle, error) {
func (h *handle) Path() (string, error) {
var stat syscall.Stat_t
if err := syscall.Stat(h.fn, &stat); err != nil {
return "", errors.Wrapf(err, "path %v could not be statted", h.fn)
return "", fmt.Errorf("path %v could not be statted: %w", h.fn, err)
}
if uint64(stat.Dev) != h.dev || uint64(stat.Ino) != h.ino { //nolint: unconvert
return "", errors.Errorf("failed to verify handle %v/%v %v/%v for %v", stat.Dev, h.dev, stat.Ino, h.ino, h.fn)
return "", fmt.Errorf("failed to verify handle %v/%v %v/%v for %v", stat.Dev, h.dev, stat.Ino, h.ino, h.fn)
}
return h.fn, nil
}
Expand Down

0 comments on commit 8343682

Please sign in to comment.