Skip to content

Commit

Permalink
Return proper error when trying to read attrs from a non-existing node
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Aug 12, 2024
1 parent 56b26dd commit 291bc4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func ReadNode(ctx context.Context, lu PathLookup, spaceID, nodeID string, canLis
spaceRoot.SpaceRoot = spaceRoot
spaceRoot.owner, err = spaceRoot.readOwner(ctx)
switch {
case metadata.IsNotExist(err):
case metadata.IsNotExist(err), metadata.IsAttrUnset(err):
return spaceRoot, nil // swallow not found, the node defaults to exists = false
case err != nil:
return nil, err
Expand Down
14 changes: 11 additions & 3 deletions pkg/storage/utils/decomposedfs/node/xattrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package node
import (
"context"
"io"
"io/fs"
"strconv"
"time"

Expand Down Expand Up @@ -144,14 +145,21 @@ func (n *Node) Xattrs(ctx context.Context) (Attributes, error) {
// Xattr returns an extended attribute of the node. If the attributes have already
// been cached it is not read from disk again.
func (n *Node) Xattr(ctx context.Context, key string) ([]byte, error) {
path := n.InternalPath()

if path == "" {
// Do not try to read the attribute of an non-existing node
return []byte{}, fs.ErrNotExist
}

if n.ID == "" {
// Do not try to read the attribute of an empty node. The InternalPath points to the
// base nodes directory in this case.
return []byte{}, &xattr.Error{Op: "node.Xattr", Path: n.InternalPath(), Name: key, Err: xattr.ENOATTR}
return []byte{}, &xattr.Error{Op: "node.Xattr", Path: path, Name: key, Err: xattr.ENOATTR}
}

if n.xattrsCache == nil {
attrs, err := n.lu.MetadataBackend().All(ctx, n.InternalPath())
attrs, err := n.lu.MetadataBackend().All(ctx, path)
if err != nil {
return []byte{}, err
}
Expand All @@ -162,7 +170,7 @@ func (n *Node) Xattr(ctx context.Context, key string) ([]byte, error) {
return val, nil
}
// wrap the error as xattr does
return []byte{}, &xattr.Error{Op: "node.Xattr", Path: n.InternalPath(), Name: key, Err: xattr.ENOATTR}
return []byte{}, &xattr.Error{Op: "node.Xattr", Path: path, Name: key, Err: xattr.ENOATTR}
}

// XattrString returns the string representation of an attribute
Expand Down

0 comments on commit 291bc4b

Please sign in to comment.