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

Commit 25a8ace

Browse files
authored
Merge pull request #76 from ipfs/fix/unlink
fix: return the correct error from RemoveChild
2 parents cb0d838 + c5e8d46 commit 25a8ace

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/ipfs/go-ipfs-posinfo v0.0.1
1212
github.com/ipfs/go-ipfs-util v0.0.1
1313
github.com/ipfs/go-ipld-format v0.0.2
14-
github.com/ipfs/go-merkledag v0.2.2
14+
github.com/ipfs/go-merkledag v0.2.3
1515
github.com/multiformats/go-multihash v0.0.5
1616
github.com/polydawn/refmt v0.0.0-20190408063855-01bf1e26dd14 // indirect
1717
github.com/smartystreets/assertions v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ github.com/ipfs/go-ipld-format v0.0.2 h1:OVAGlyYT6JPZ0pEfGntFPS40lfrDmaDbQwNHEY2
114114
github.com/ipfs/go-ipld-format v0.0.2/go.mod h1:4B6+FM2u9OJ9zCV+kSbgFAZlOrv1Hqbf0INGQgiKf9k=
115115
github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc=
116116
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
117-
github.com/ipfs/go-merkledag v0.2.2 h1:cw3eEYSH8L1gGa+HTDB08Q7hh5EUfztKf075JIlg5ww=
118-
github.com/ipfs/go-merkledag v0.2.2/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB3ClKnBAlk=
117+
github.com/ipfs/go-merkledag v0.2.3 h1:aMdkK9G1hEeNvn3VXfiEMLY0iJnbiQQUHnM0HFJREsE=
118+
github.com/ipfs/go-merkledag v0.2.3/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB3ClKnBAlk=
119119
github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fGD6n0jO4kdg=
120120
github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY=
121121
github.com/ipfs/go-peertaskqueue v0.1.0 h1:bpRbgv76eT4avutNPDFZuCPOQus6qTgurEYxfulgZW4=

hamt/hamt.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ func (ds *Shard) Set(ctx context.Context, name string, nd ipld.Node) error {
221221
return ds.modifyValue(ctx, hv, name, lnk)
222222
}
223223

224-
// Remove deletes the named entry if it exists, this operation is idempotent.
224+
// Remove deletes the named entry if it exists. Otherwise, it returns
225+
// os.ErrNotExist.
225226
func (ds *Shard) Remove(ctx context.Context, name string) error {
226227
hv := &hashBits{b: hash([]byte(name))}
227228
return ds.modifyValue(ctx, hv, name, nil)

io/directory.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ type Directory interface {
4848

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

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

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

197201
// RemoveChild implements the `Directory` interface.
198202
func (d *BasicDirectory) RemoveChild(ctx context.Context, name string) error {
199-
return d.node.RemoveNodeLink(name)
203+
err := d.node.RemoveNodeLink(name)
204+
if err == mdag.ErrLinkNotFound {
205+
err = os.ErrNotExist
206+
}
207+
return err
200208
}
201209

202210
// GetNode implements the `Directory` interface.

0 commit comments

Comments
 (0)