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
90f6f5f0
Commit
90f6f5f0
authored
Sep 30, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address comments from CR
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
428e8f9d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
4 deletions
+63
-4
mod/dagmodifier.go
mod/dagmodifier.go
+16
-4
mod/dagmodifier_test.go
mod/dagmodifier_test.go
+47
-0
No files found.
mod/dagmodifier.go
View file @
90f6f5f0
...
...
@@ -368,19 +368,31 @@ func (dm *DagModifier) Seek(offset int64, whence int) (int64, error) {
return
0
,
err
}
fisize
,
err
:=
dm
.
Size
()
if
err
!=
nil
{
return
0
,
err
}
var
newoffset
uint64
switch
whence
{
case
os
.
SEEK_CUR
:
dm
.
curWrOff
+=
uint64
(
offset
)
dm
.
writeStart
=
dm
.
curWrOff
newoffset
=
dm
.
curWrOff
+
uint64
(
offset
)
case
os
.
SEEK_SET
:
dm
.
curWrOff
=
uint64
(
offset
)
dm
.
writeStart
=
uint64
(
offset
)
newoffset
=
uint64
(
offset
)
case
os
.
SEEK_END
:
return
0
,
ErrSeekEndNotImpl
default
:
return
0
,
ErrUnrecognizedWhence
}
if
offset
>
fisize
{
if
err
:=
dm
.
expandSparse
(
offset
-
fisize
);
err
!=
nil
{
return
0
,
err
}
}
dm
.
curWrOff
=
newoffset
dm
.
writeStart
=
newoffset
if
dm
.
read
!=
nil
{
_
,
err
=
dm
.
read
.
Seek
(
offset
,
whence
)
if
err
!=
nil
{
...
...
mod/dagmodifier_test.go
View file @
90f6f5f0
...
...
@@ -487,6 +487,53 @@ func TestSparseWrite(t *testing.T) {
}
}
func
TestSeekPastEndWrite
(
t
*
testing
.
T
)
{
dserv
:=
getMockDagServ
(
t
)
_
,
n
:=
getNode
(
t
,
dserv
,
0
)
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
dagmod
,
err
:=
NewDagModifier
(
ctx
,
n
,
dserv
,
sizeSplitterGen
(
512
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
buf
:=
make
([]
byte
,
5000
)
u
.
NewTimeSeededRand
()
.
Read
(
buf
[
2500
:
])
nseek
,
err
:=
dagmod
.
Seek
(
2500
,
os
.
SEEK_SET
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
nseek
!=
2500
{
t
.
Fatal
(
"failed to seek"
)
}
wrote
,
err
:=
dagmod
.
Write
(
buf
[
2500
:
])
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
wrote
!=
2500
{
t
.
Fatal
(
"incorrect write amount"
)
}
_
,
err
=
dagmod
.
Seek
(
0
,
os
.
SEEK_SET
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
out
,
err
:=
ioutil
.
ReadAll
(
dagmod
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
=
arrComp
(
out
,
buf
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
func
BenchmarkDagmodWrite
(
b
*
testing
.
B
)
{
b
.
StopTimer
()
dserv
:=
getMockDagServ
(
b
)
...
...
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