From c5e8d46322d98839db850f1031824ab1cb0ed912 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 25 Jul 2019 19:06:15 -0700 Subject: [PATCH] fix: return the correct error from RemoveChild --- go.mod | 2 +- go.sum | 4 ++-- hamt/hamt.go | 3 ++- io/directory.go | 10 +++++++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 99af9f0d2..c890902ec 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/ipfs/go-ipfs-posinfo v0.0.1 github.com/ipfs/go-ipfs-util v0.0.1 github.com/ipfs/go-ipld-format v0.0.2 - github.com/ipfs/go-merkledag v0.2.2 + github.com/ipfs/go-merkledag v0.2.3 github.com/multiformats/go-multihash v0.0.5 github.com/polydawn/refmt v0.0.0-20190408063855-01bf1e26dd14 // indirect github.com/smartystreets/assertions v1.0.0 // indirect diff --git a/go.sum b/go.sum index a678ecc3b..46d1f2d26 100644 --- a/go.sum +++ b/go.sum @@ -114,8 +114,8 @@ github.com/ipfs/go-ipld-format v0.0.2 h1:OVAGlyYT6JPZ0pEfGntFPS40lfrDmaDbQwNHEY2 github.com/ipfs/go-ipld-format v0.0.2/go.mod h1:4B6+FM2u9OJ9zCV+kSbgFAZlOrv1Hqbf0INGQgiKf9k= github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= -github.com/ipfs/go-merkledag v0.2.2 h1:cw3eEYSH8L1gGa+HTDB08Q7hh5EUfztKf075JIlg5ww= -github.com/ipfs/go-merkledag v0.2.2/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB3ClKnBAlk= +github.com/ipfs/go-merkledag v0.2.3 h1:aMdkK9G1hEeNvn3VXfiEMLY0iJnbiQQUHnM0HFJREsE= +github.com/ipfs/go-merkledag v0.2.3/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB3ClKnBAlk= github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fGD6n0jO4kdg= github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY= github.com/ipfs/go-peertaskqueue v0.1.0 h1:bpRbgv76eT4avutNPDFZuCPOQus6qTgurEYxfulgZW4= diff --git a/hamt/hamt.go b/hamt/hamt.go index 9bf67505b..6b89b47c7 100644 --- a/hamt/hamt.go +++ b/hamt/hamt.go @@ -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) diff --git a/io/directory.go b/io/directory.go index 2e0227623..f773704a2 100644 --- a/io/directory.go +++ b/io/directory.go @@ -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.