Skip to content

Commit

Permalink
Fix/parent without stat (#3975)
Browse files Browse the repository at this point in the history
* drop stat and use return code from XattrsWithReader

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

* add changelog

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

---------

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic authored Jun 15, 2023
1 parent 186dd7c commit 91643f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/parent-without-stat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: decomposedfs now resolves the parent without an os.Stat

https://github.com/cs3org/reva/pull/3975
24 changes: 13 additions & 11 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,29 +406,31 @@ func (n *Node) Child(ctx context.Context, name string) (*Node, error) {
}

// ParentWithReader returns the parent node
func (n *Node) ParentWithReader(r io.Reader) (p *Node, err error) {
func (n *Node) ParentWithReader(r io.Reader) (*Node, error) {
if n.ParentID == "" {
return nil, fmt.Errorf("decomposedfs: root has no parent")
}
p = &Node{
p := &Node{
SpaceID: n.SpaceID,
lu: n.lu,
ID: n.ParentID,
SpaceRoot: n.SpaceRoot,
}

// fill metadata cache using the reader
_, _ = p.XattrsWithReader(r)
attrs, err := p.XattrsWithReader(r)
switch {
case metadata.IsNotExist(err):
return p, nil // swallow not found, the node defaults to exists = false
case err != nil:
return nil, err
}
p.Exists = true

// lookup name and parent id in extended attributes
p.ParentID, _ = p.XattrString(prefixes.ParentidAttr)
p.Name, _ = p.XattrString(prefixes.NameAttr)
p.Name = attrs.String(prefixes.NameAttr)
p.ParentID = attrs.String(prefixes.ParentidAttr)

// check node exists
if _, err := os.Stat(p.InternalPath()); err == nil {
p.Exists = true
}
return
return p, err
}

// Parent returns the parent node
Expand Down

0 comments on commit 91643f9

Please sign in to comment.