From 132afbe83bd18bea0a53129363ef22f9ae8a7c31 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 18 Feb 2017 11:35:04 +0100 Subject: [PATCH] Correct error check for ENOTSUP, add errors.Wrap() --- src/restic/node.go | 5 ++--- src/restic/node_xattr.go | 13 +++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/restic/node.go b/src/restic/node.go index 5e7e35a1f..493929dc7 100644 --- a/src/restic/node.go +++ b/src/restic/node.go @@ -577,9 +577,8 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error { case "symlink": node.LinkTarget, err = fs.Readlink(path) node.Links = uint64(stat.nlink()) - err = errors.Wrap(err, "Readlink") if err != nil { - return err + return errors.Wrap(err, "Readlink") } case "dev": node.Device = uint64(stat.rdev()) @@ -597,7 +596,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error { return err } - return err + return nil } func (node *Node) fillExtendedAttributes(path string) error { diff --git a/src/restic/node_xattr.go b/src/restic/node_xattr.go index ae1c6443f..a61c44a97 100644 --- a/src/restic/node_xattr.go +++ b/src/restic/node_xattr.go @@ -4,6 +4,7 @@ package restic import ( + "restic/errors" "syscall" "github.com/pkg/xattr" @@ -12,27 +13,27 @@ import ( // Getxattr retrieves extended attribute data associated with path. func Getxattr(path, name string) ([]byte, error) { b, e := xattr.Getxattr(path, name) - if e == syscall.ENOTSUP { + if err, ok := e.(*xattr.XAttrError); ok && err.Err == syscall.ENOTSUP { return nil, nil } - return b, e + return b, errors.Wrap(e, "Getxattr") } // Listxattr retrieves a list of names of extended attributes associated with the // given path in the file system. func Listxattr(path string) ([]string, error) { s, e := xattr.Listxattr(path) - if e == syscall.ENOTSUP { + if err, ok := e.(*xattr.XAttrError); ok && err.Err == syscall.ENOTSUP { return nil, nil } - return s, e + return s, errors.Wrap(e, "Listxattr") } // Setxattr associates name and data together as an attribute of path. func Setxattr(path, name string, data []byte) error { e := xattr.Setxattr(path, name, data) - if e == syscall.ENOTSUP { + if err, ok := e.(*xattr.XAttrError); ok && err.Err == syscall.ENOTSUP { return nil } - return e + return errors.Wrap(e, "Setxattr") }