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
f573b7b5
Commit
f573b7b5
authored
6 years ago
by
Kejie Zhang
Committed by
Lucas Molas
6 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correctly handle offsets bigger than file size
parent
4973eab0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
1 deletion
+60
-1
mod/dagmodifier.go
mod/dagmodifier.go
+11
-1
mod/dagmodifier_test.go
mod/dagmodifier_test.go
+49
-0
No files found.
mod/dagmodifier.go
View file @
f573b7b5
...
...
@@ -200,6 +200,16 @@ func (dm *DagModifier) Sync() error {
// Number of bytes we're going to write
buflen
:=
dm
.
wrBuf
.
Len
()
fs
,
err
:=
fileSize
(
dm
.
curNode
)
if
err
!=
nil
{
return
err
}
if
fs
<
dm
.
writeStart
{
if
err
:=
dm
.
expandSparse
(
int64
(
dm
.
writeStart
-
fs
));
err
!=
nil
{
return
err
}
}
// overwrite existing dag nodes
thisc
,
err
:=
dm
.
modifyDag
(
dm
.
curNode
,
dm
.
writeStart
)
if
err
!=
nil
{
...
...
@@ -225,8 +235,8 @@ func (dm *DagModifier) Sync() error {
}
dm
.
writeStart
+=
uint64
(
buflen
)
dm
.
wrBuf
=
nil
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
mod/dagmodifier_test.go
View file @
f573b7b5
...
...
@@ -7,12 +7,14 @@ import (
"io/ioutil"
"testing"
dag "github.com/ipfs/go-merkledag"
h "github.com/ipfs/go-unixfs/importer/helpers"
trickle "github.com/ipfs/go-unixfs/importer/trickle"
uio "github.com/ipfs/go-unixfs/io"
testu "github.com/ipfs/go-unixfs/test"
u "github.com/ipfs/go-ipfs-util"
"github.com/ipfs/go-unixfs"
)
func testModWrite(t *testing.T, beg, size uint64, orig []byte, dm *DagModifier, opts testu.NodeOpts) []byte {
...
...
@@ -410,6 +412,53 @@ func testDagTruncate(t *testing.T, opts testu.NodeOpts) {
}
}
func TestDagSync(t *testing.T) {
dserv := testu.GetDAGServ()
nd := dag.NodeWithData(unixfs.FilePBData(nil, 0))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
dagmod, err := NewDagModifier(ctx, nd, dserv, testu.SizeSplitterGen(512))
if err != nil {
t.Fatal(err)
}
_, err = dagmod.Write([]byte("test1"))
if err != nil {
t.Fatal(err)
}
err = dagmod.Sync()
if err != nil {
t.Fatal(err)
}
err = dagmod.Truncate(0)
if err != nil {
t.Fatal(err)
}
_, err = dagmod.Write([]byte("test2"))
if err != nil {
t.Fatal(err)
}
err = dagmod.Sync()
if err != nil {
t.Fatal(err)
}
out, err := ioutil.ReadAll(dagmod)
if err != nil {
t.Fatal(err)
}
if err = testu.ArrComp(out[5:], []byte("test2")); err != nil {
t.Fatal(err)
}
}
// TestDagTruncateSameSize tests that a DAG truncated
// to the same size (i.e., doing nothing) doesn't modify
// the DAG (its hash).
...
...
This diff is collapsed.
Click to expand it.
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