Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
47001548
提交
47001548
authored
6月 20, 2017
作者:
Kevin Atkinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish basic support for raw nodes in dag modifier.
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
上级
c75ac6a7
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
57 行增加
和
17 行删除
+57
-17
t0250-files-api.sh
test/sharness/t0250-files-api.sh
+37
-0
dagmodifier.go
unixfs/mod/dagmodifier.go
+18
-16
dagmodifier_test.go
unixfs/mod/dagmodifier_test.go
+2
-1
没有找到文件。
test/sharness/t0250-files-api.sh
浏览文件 @
47001548
...
...
@@ -15,6 +15,7 @@ test_expect_success "can create some files for testing" '
FILE1=$(echo foo | ipfs add -q) &&
FILE2=$(echo bar | ipfs add -q) &&
FILE3=$(echo baz | ipfs add -q) &&
FILE9=$(echo zip | ipfs add -q --raw-leaves) &&
mkdir stuff_test &&
echo cats > stuff_test/a &&
echo dogs > stuff_test/b &&
...
...
@@ -252,6 +253,42 @@ test_files_api() {
test_cmp roothash roothashafter
'
# test raw node
test_expect_success
"can put a raw-node into root"
'
ipfs files cp /ipfs/$FILE9 /file9
'
test_expect_success
"file shows up in root"
'
verify_dir_contents / file9 cats
'
test_expect_success
"can read file"
'
ipfs files read /file9 > file9out
'
test_expect_success
"output looks good"
'
echo zip > expected &&
test_cmp expected file9out
'
test_expect_success
"can remove file from root"
'
ipfs files rm /file9
'
test_expect_success
"file no longer appears"
'
verify_dir_contents / cats
'
test_expect_success
"check root hash"
'
ipfs files stat --hash / > roothash
'
test_expect_success
"check root hash was not changed"
'
ipfs files stat --hash / > roothashafter &&
test_cmp roothash roothashafter
'
# test read options
test_expect_success
"read from offset works"
'
...
...
unixfs/mod/dagmodifier.go
浏览文件 @
47001548
...
...
@@ -152,23 +152,25 @@ func (dm *DagModifier) Write(b []byte) (int, error) {
var
ErrNoRawYet
=
fmt
.
Errorf
(
"currently only fully support protonodes in the dagmodifier"
)
func
(
dm
*
DagModifier
)
Size
()
(
int64
,
error
)
{
pbnd
,
ok
:=
dm
.
curNode
.
(
*
mdag
.
ProtoNode
)
if
!
ok
{
return
0
,
ErrNoRawYet
}
pbn
,
err
:=
ft
.
FromBytes
(
pbnd
.
Data
())
if
err
!=
nil
{
return
0
,
err
}
if
dm
.
wrBuf
!=
nil
{
if
uint64
(
dm
.
wrBuf
.
Len
())
+
dm
.
writeStart
>
pbn
.
GetFilesize
()
{
switch
nd
:=
dm
.
curNode
.
(
type
)
{
case
*
mdag
.
ProtoNode
:
pbn
,
err
:=
ft
.
FromBytes
(
nd
.
Data
())
if
err
!=
nil
{
return
0
,
err
}
if
dm
.
wrBuf
!=
nil
&&
uint64
(
dm
.
wrBuf
.
Len
())
+
dm
.
writeStart
>
pbn
.
GetFilesize
()
{
return
int64
(
dm
.
wrBuf
.
Len
())
+
int64
(
dm
.
writeStart
),
nil
}
return
int64
(
pbn
.
GetFilesize
()),
nil
case
*
mdag
.
RawNode
:
if
dm
.
wrBuf
!=
nil
{
return
0
,
ErrNoRawYet
}
sz
,
err
:=
nd
.
Size
()
return
int64
(
sz
),
err
default
:
return
0
,
ErrNotUnixfs
}
return
int64
(
pbn
.
GetFilesize
()),
nil
}
// Sync writes changes to this dag to disk
...
...
@@ -397,12 +399,12 @@ func (dm *DagModifier) CtxReadFull(ctx context.Context, b []byte) (int, error) {
}
// GetNode gets the modified DAG Node
func
(
dm
*
DagModifier
)
GetNode
()
(
*
mdag
.
Proto
Node
,
error
)
{
func
(
dm
*
DagModifier
)
GetNode
()
(
node
.
Node
,
error
)
{
err
:=
dm
.
Sync
()
if
err
!=
nil
{
return
nil
,
err
}
return
dm
.
curNode
.
Copy
()
.
(
*
mdag
.
ProtoNode
)
,
nil
return
dm
.
curNode
.
Copy
(),
nil
}
// HasChanges returned whether or not there are unflushed changes to this dag
...
...
unixfs/mod/dagmodifier_test.go
浏览文件 @
47001548
...
...
@@ -9,6 +9,7 @@ import (
h
"github.com/ipfs/go-ipfs/importer/helpers"
trickle
"github.com/ipfs/go-ipfs/importer/trickle"
mdag
"github.com/ipfs/go-ipfs/merkledag"
ft
"github.com/ipfs/go-ipfs/unixfs"
uio
"github.com/ipfs/go-ipfs/unixfs/io"
testu
"github.com/ipfs/go-ipfs/unixfs/test"
...
...
@@ -105,7 +106,7 @@ func TestDagModifierBasic(t *testing.T) {
t
.
Fatal
(
err
)
}
size
,
err
:=
ft
.
DataSize
(
node
.
Data
())
size
,
err
:=
ft
.
DataSize
(
node
.
(
*
mdag
.
ProtoNode
)
.
Data
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论