Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #76 from ipfs/fix/unlink
Browse files Browse the repository at this point in the history
fix: return the correct error from RemoveChild
  • Loading branch information
Stebalien committed Jul 26, 2019
2 parents cb0d838 + c5e8d46 commit 25a8ace
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion 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 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 25a8ace

Please sign in to comment.