Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
f1728295
Unverified
Commit
f1728295
authored
Feb 07, 2020
by
Steven Allen
Committed by
GitHub
Feb 07, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #81 from ipfs/fix/panic-on-delete
fix: fix a panic when deleting
parents
da35b26a
af8709db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
3 deletions
+68
-3
hamt/hamt.go
hamt/hamt.go
+29
-3
hamt/hamt_test.go
hamt/hamt_test.go
+39
-0
No files found.
hamt/hamt.go
View file @
f1728295
...
@@ -489,10 +489,28 @@ func (ds *Shard) modifyValue(ctx context.Context, hv *hashBits, key string, val
...
@@ -489,10 +489,28 @@ func (ds *Shard) modifyValue(ctx context.Context, hv *hashBits, key string, val
// structures, this will help to normalize them.
// structures, this will help to normalize them.
return
ds
.
childer
.
rm
(
idx
)
return
ds
.
childer
.
rm
(
idx
)
case
1
:
case
1
:
nchild
:=
child
.
childer
.
children
[
0
]
// The single child _should_ be a value by
if
nchild
.
isValueNode
()
{
// induction. However, we allow for it to be a
// shard in case an implementation is broken.
// Have we loaded the child? Prefer that.
schild
:=
child
.
childer
.
child
(
0
)
if
schild
!=
nil
{
if
schild
.
isValueNode
()
{
ds
.
childer
.
set
(
schild
,
i
)
}
return
nil
}
// Otherwise, work with the link.
slnk
:=
child
.
childer
.
link
(
0
)
lnkType
,
err
:=
child
.
childer
.
sd
.
childLinkType
(
slnk
)
if
err
!=
nil
{
return
err
}
if
lnkType
==
shardValueLink
{
// sub-shard with a single value element, collapse it
// sub-shard with a single value element, collapse it
ds
.
childer
.
set
(
nchild
,
i
)
ds
.
childer
.
set
Link
(
slnk
,
i
)
}
}
return
nil
return
nil
}
}
...
@@ -517,6 +535,8 @@ type childer struct {
...
@@ -517,6 +535,8 @@ type childer struct {
sd
*
Shard
sd
*
Shard
dserv
ipld
.
DAGService
dserv
ipld
.
DAGService
bitfield
bitfield
.
Bitfield
bitfield
bitfield
.
Bitfield
// Only one of links/children will be non-nil for every child/link.
links
[]
*
ipld
.
Link
links
[]
*
ipld
.
Link
children
[]
*
Shard
children
[]
*
Shard
}
}
...
@@ -572,6 +592,12 @@ func (s *childer) insert(key string, lnk *ipld.Link, idx int) error {
...
@@ -572,6 +592,12 @@ func (s *childer) insert(key string, lnk *ipld.Link, idx int) error {
func
(
s
*
childer
)
set
(
sd
*
Shard
,
i
int
)
{
func
(
s
*
childer
)
set
(
sd
*
Shard
,
i
int
)
{
s
.
children
[
i
]
=
sd
s
.
children
[
i
]
=
sd
s
.
links
[
i
]
=
nil
}
func
(
s
*
childer
)
setLink
(
lnk
*
ipld
.
Link
,
i
int
)
{
s
.
children
[
i
]
=
nil
s
.
links
[
i
]
=
lnk
}
}
func
(
s
*
childer
)
rm
(
childIndex
int
)
error
{
func
(
s
*
childer
)
rm
(
childIndex
int
)
error
{
...
...
hamt/hamt_test.go
View file @
f1728295
...
@@ -268,6 +268,45 @@ func TestRemoveElems(t *testing.T) {
...
@@ -268,6 +268,45 @@ func TestRemoveElems(t *testing.T) {
}
}
}
}
func
TestRemoveAfterMarshal
(
t
*
testing
.
T
)
{
ds
:=
mdtest
.
Mock
()
dirs
,
s
,
err
:=
makeDir
(
ds
,
500
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
nd
,
err
:=
s
.
Node
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
s
,
err
=
NewHamtFromDag
(
ds
,
nd
)
ctx
:=
context
.
Background
()
shuffle
(
time
.
Now
()
.
UnixNano
(),
dirs
)
for
i
,
d
:=
range
dirs
{
err
:=
s
.
Remove
(
ctx
,
d
)
if
err
!=
nil
{
t
.
Fatalf
(
"%d/%d: %s"
,
i
,
len
(
dirs
),
err
)
}
}
nd
,
err
=
s
.
Node
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
nd
.
Links
())
>
0
{
t
.
Fatal
(
"shouldnt have any links here"
)
}
err
=
s
.
Remove
(
ctx
,
"doesnt exist"
)
if
err
!=
os
.
ErrNotExist
{
t
.
Fatal
(
"expected error does not exist"
)
}
}
func
TestSetAfterMarshal
(
t
*
testing
.
T
)
{
func
TestSetAfterMarshal
(
t
*
testing
.
T
)
{
ds
:=
mdtest
.
Mock
()
ds
:=
mdtest
.
Mock
()
_
,
s
,
err
:=
makeDir
(
ds
,
300
)
_
,
s
,
err
:=
makeDir
(
ds
,
300
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment