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

harden xattrs errors #2576

Merged
merged 2 commits into from
Feb 22, 2022
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
2 changes: 1 addition & 1 deletion .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def lintStep():
"name": "lint",
"image": "registry.cern.ch/docker.io/golangci/golangci-lint:v1.42.1",
"commands": [
"golangci-lint run --timeout 2m0s",
"golangci-lint run --timeout 3m0s",
],
}

Expand Down
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