Unverified Commit 25a8aced authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #76 from ipfs/fix/unlink

fix: return the correct error from RemoveChild
parents cb0d838f c5e8d463
......@@ -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)
......
......@@ -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.
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment