Skip to content

Commit

Permalink
Merge pull request ipfs/go-unixfs#76 from ipfs/fix/unlink
Browse files Browse the repository at this point in the history
fix: return the correct error from RemoveChild

This commit was moved from ipfs/go-unixfs@25a8ace
  • Loading branch information
Stebalien authored Jul 26, 2019
2 parents 2900da0 + c001260 commit e90e27d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion unixfs/ipld-merkledag/hamt/hamt.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ func (ds *Shard) Set(ctx context.Context, name string, nd ipld.Node) error {
return ds.modifyValue(ctx, hv, name, lnk)
}

// Remove deletes the named entry if it exists, this operation is idempotent.
// Remove deletes the named entry if it exists. Otherwise, it returns
// os.ErrNotExist.
func (ds *Shard) Remove(ctx context.Context, name string) error {
hv := &hashBits{b: hash([]byte(name))}
return ds.modifyValue(ctx, hv, name, nil)
Expand Down
10 changes: 9 additions & 1 deletion unixfs/ipld-merkledag/io/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ type Directory interface {

// Find returns the root node of the file named 'name' within this directory.
// In the case of HAMT-directories, it will traverse the tree.
//
// Returns os.ErrNotExist if the child does not exist.
Find(context.Context, string) (ipld.Node, error)

// RemoveChild removes the child with the given name.
//
// Returns os.ErrNotExist if the child doesn't exist.
RemoveChild(context.Context, string) error

// GetNode returns the root of this directory.
Expand Down Expand Up @@ -196,7 +200,11 @@ func (d *BasicDirectory) Find(ctx context.Context, name string) (ipld.Node, erro

// RemoveChild implements the `Directory` interface.
func (d *BasicDirectory) RemoveChild(ctx context.Context, name string) error {
return d.node.RemoveNodeLink(name)
err := d.node.RemoveNodeLink(name)
if err == mdag.ErrLinkNotFound {
err = os.ErrNotExist
}
return err
}

// GetNode implements the `Directory` interface.
Expand Down

0 comments on commit e90e27d

Please sign in to comment.