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
Oct 12, 2018
by
Kejie Zhang
Committed by
Lucas Molas
Oct 29, 2018
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 {
...
@@ -200,6 +200,16 @@ func (dm *DagModifier) Sync() error {
// Number of bytes we're going to write
// Number of bytes we're going to write
buflen
:=
dm
.
wrBuf
.
Len
()
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
// overwrite existing dag nodes
thisc
,
err
:=
dm
.
modifyDag
(
dm
.
curNode
,
dm
.
writeStart
)
thisc
,
err
:=
dm
.
modifyDag
(
dm
.
curNode
,
dm
.
writeStart
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -225,8 +235,8 @@ func (dm *DagModifier) Sync() error {
...
@@ -225,8 +235,8 @@ func (dm *DagModifier) Sync() error {
}
}
dm
.
writeStart
+=
uint64
(
buflen
)
dm
.
writeStart
+=
uint64
(
buflen
)
dm
.
wrBuf
=
nil
dm
.
wrBuf
=
nil
return
nil
return
nil
}
}
...
...
mod/dagmodifier_test.go
View file @
f573b7b5
...
@@ -7,12 +7,14 @@ import (
...
@@ -7,12 +7,14 @@ import (
"io/ioutil"
"io/ioutil"
"testing"
"testing"
dag
"github.com/ipfs/go-merkledag"
h
"github.com/ipfs/go-unixfs/importer/helpers"
h
"github.com/ipfs/go-unixfs/importer/helpers"
trickle
"github.com/ipfs/go-unixfs/importer/trickle"
trickle
"github.com/ipfs/go-unixfs/importer/trickle"
uio
"github.com/ipfs/go-unixfs/io"
uio
"github.com/ipfs/go-unixfs/io"
testu
"github.com/ipfs/go-unixfs/test"
testu
"github.com/ipfs/go-unixfs/test"
u
"github.com/ipfs/go-ipfs-util"
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
{
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) {
...
@@ -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
// TestDagTruncateSameSize tests that a DAG truncated
// to the same size (i.e., doing nothing) doesn't modify
// to the same size (i.e., doing nothing) doesn't modify
// the DAG (its hash).
// the DAG (its hash).
...
...
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