Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace pkg/errors #35

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions btrfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ static char* get_name_btrfs_ioctl_vol_args_v2(struct btrfs_ioctl_vol_args_v2* bt
import "C"

import (
"errors"
"fmt"
"os"
"path/filepath"
"sort"
"syscall"
"unsafe"

"github.com/pkg/errors"
)

// maxByteSliceSize is the smallest size that Go supports on various platforms.
Expand Down Expand Up @@ -99,7 +99,7 @@ func SubvolInfo(path string) (info Info, err error) {
return *info, nil
}

return info, errors.Errorf("%q not found", path)
return info, fmt.Errorf("%q not found", path)
}

func subvolMap(path string) (map[uint64]*Info, error) {
Expand Down Expand Up @@ -273,13 +273,13 @@ func SubvolCreate(path string) error {
args.fd = C.__s64(fp.Fd())

if len(name) > C.BTRFS_PATH_NAME_MAX {
return errors.Errorf("%q too long for subvolume", name)
return fmt.Errorf("%q too long for subvolume", name)
}
nameptr := (*[maxByteSliceSize]byte)(unsafe.Pointer(&args.name[0]))[:C.BTRFS_PATH_NAME_MAX:C.BTRFS_PATH_NAME_MAX]
copy(nameptr[:C.BTRFS_PATH_NAME_MAX], []byte(name))

if err := ioctl(fp.Fd(), C.BTRFS_IOC_SUBVOL_CREATE, uintptr(unsafe.Pointer(&args))); err != nil {
return errors.Wrap(err, "btrfs subvolume create failed")
return fmt.Errorf("btrfs subvolume create failed: %w", err)
}

return nil
Expand All @@ -292,13 +292,13 @@ func SubvolSnapshot(dst, src string, readonly bool) error {

dstfp, err := openSubvolDir(dstdir)
if err != nil {
return errors.Wrapf(err, "opening snapshot destination subvolume failed")
return fmt.Errorf("opening snapshot destination subvolume failed: %w", err)
}
defer dstfp.Close()

srcfp, err := openSubvolDir(src)
if err != nil {
return errors.Wrapf(err, "opening snapshot source subvolume failed")
return fmt.Errorf("opening snapshot source subvolume failed: %w", err)
}
defer srcfp.Close()

Expand All @@ -308,7 +308,7 @@ func SubvolSnapshot(dst, src string, readonly bool) error {
name := C.get_name_btrfs_ioctl_vol_args_v2(&args)

if len(dstname) > C.BTRFS_SUBVOL_NAME_MAX {
return errors.Errorf("%q too long for subvolume", dstname)
return fmt.Errorf("%q too long for subvolume", dstname)
}

nameptr := (*[maxByteSliceSize]byte)(unsafe.Pointer(name))[:C.BTRFS_SUBVOL_NAME_MAX:C.BTRFS_SUBVOL_NAME_MAX]
Expand All @@ -319,7 +319,7 @@ func SubvolSnapshot(dst, src string, readonly bool) error {
}

if err := ioctl(dstfp.Fd(), C.BTRFS_IOC_SNAP_CREATE_V2, uintptr(unsafe.Pointer(&args))); err != nil {
return errors.Wrapf(err, "snapshot create failed")
return fmt.Errorf("snapshot create failed: %w", err)
}

return nil
Expand All @@ -330,7 +330,7 @@ func SubvolDelete(path string) error {
dir, name := filepath.Split(path)
fp, err := openSubvolDir(dir)
if err != nil {
return errors.Wrapf(err, "failed opening %v", path)
return fmt.Errorf("failed opening %v: %w", path, err)
}
defer fp.Close()

Expand All @@ -341,7 +341,7 @@ func SubvolDelete(path string) error {
return nil
}

return errors.Wrapf(err, "failed walking subvolume %v", p)
return fmt.Errorf("failed walking subvolume %v: %w", p, err)
}

if !fi.IsDir() {
Expand All @@ -357,7 +357,7 @@ func SubvolDelete(path string) error {
}

if err := SubvolDelete(p); err != nil {
return errors.Wrapf(err, "recursive delete of %v failed", p)
return fmt.Errorf("recursive delete of %v failed: %w", p, err)
}

return filepath.SkipDir // children get walked by call above.
Expand All @@ -367,14 +367,14 @@ func SubvolDelete(path string) error {

var args C.struct_btrfs_ioctl_vol_args
if len(name) > C.BTRFS_SUBVOL_NAME_MAX {
return errors.Errorf("%q too long for subvolume", name)
return fmt.Errorf("%q too long for subvolume", name)
}

nameptr := (*[maxByteSliceSize]byte)(unsafe.Pointer(&args.name[0]))[:C.BTRFS_SUBVOL_NAME_MAX:C.BTRFS_SUBVOL_NAME_MAX]
copy(nameptr[:C.BTRFS_SUBVOL_NAME_MAX], []byte(name))

if err := ioctl(fp.Fd(), C.BTRFS_IOC_SNAP_DESTROY, uintptr(unsafe.Pointer(&args))); err != nil {
return errors.Wrapf(err, "failed removing subvolume %v", path)
return fmt.Errorf("failed removing subvolume %v: %w", path, err)
}

return nil
Expand All @@ -383,29 +383,29 @@ func SubvolDelete(path string) error {
func openSubvolDir(path string) (*os.File, error) {
fp, err := os.Open(path)
if err != nil {
return nil, errors.Wrapf(err, "opening %v as subvolume failed", path)
return nil, fmt.Errorf("opening %v as subvolume failed: %w", path, err)
}

return fp, nil
}

func isStatfsSubvol(statfs *syscall.Statfs_t) error {
if int64(statfs.Type) != int64(C.BTRFS_SUPER_MAGIC) {
return errors.Errorf("not a btrfs filesystem")
return fmt.Errorf("not a btrfs filesystem")
}

return nil
}

func isFileInfoSubvol(fi os.FileInfo) error {
if !fi.IsDir() {
errors.Errorf("must be a directory")
return errors.New("must be a directory")
}

stat := fi.Sys().(*syscall.Stat_t)

if stat.Ino != C.BTRFS_FIRST_FREE_OBJECTID {
return errors.Errorf("incorrect inode type")
return fmt.Errorf("incorrect inode type")
}

return nil
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/containerd/btrfs

go 1.15

require github.com/pkg/errors v0.9.1
go 1.16
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
4 changes: 1 addition & 3 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (
"os"
"strings"
"unsafe"

"github.com/pkg/errors"
)

func subvolID(fd uintptr) (uint64, error) {
Expand Down Expand Up @@ -95,7 +93,7 @@ func findMountPoint(path string) (string, error) {
}

if mount == "" {
return "", errors.Errorf("mount point of %v not found", path)
return "", fmt.Errorf("mount point of %v not found", path)
}

return mount, nil
Expand Down