Skip to content

Commit

Permalink
harden xattrs errors
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Feb 21, 2022
1 parent 8cc813e commit 6863f68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/harden-xattrs-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: Harden xattrs errors

Unwrap the error to get the root error.

https://github.com/cs3org/reva/pull/2576
5 changes: 3 additions & 2 deletions pkg/storage/utils/decomposedfs/xattrs/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ package xattrs
import (
"syscall"

"github.com/pkg/errors"
"github.com/pkg/xattr"
)

// IsNotExist checks if there is a os not exists error buried inside the xattr error,
// as we cannot just use os.IsNotExist().
func IsNotExist(err error) bool {
if xerr, ok := err.(*xattr.Error); ok {
if xerr, ok := errors.Cause(err).(*xattr.Error); ok {
if serr, ok2 := xerr.Err.(syscall.Errno); ok2 {
return serr == syscall.ENOENT
}
Expand All @@ -38,7 +39,7 @@ func IsNotExist(err error) bool {
// IsAttrUnset checks the xattr.ENOATTR from the xattr package which redifines it as ENODATA on platforms that do not natively support it (eg. linux)
// see https://github.com/pkg/xattr/blob/8725d4ccc0fcef59c8d9f0eaf606b3c6f962467a/xattr_linux.go#L19-L22
func IsAttrUnset(err error) bool {
if xerr, ok := err.(*xattr.Error); ok {
if xerr, ok := errors.Cause(err).(*xattr.Error); ok {
if serr, ok2 := xerr.Err.(syscall.Errno); ok2 {
return serr == xattr.ENOATTR
}
Expand Down

0 comments on commit 6863f68

Please sign in to comment.