Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
f5f5700d
提交
f5f5700d
authored
2月 01, 2015
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #712 from jbenet/cat-length-fix
cat length output now uses unixfs size
上级
4539b977
5b0a544b
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
126 行增加
和
28 行删除
+126
-28
cat.go
core/commands/cat.go
+1
-6
test-lib.sh
test/sharness/lib/test-lib.sh
+50
-13
t0021-config.sh
test/sharness/t0021-config.sh
+60
-0
t0090-get.sh
test/sharness/t0090-get.sh
+3
-1
t0110-gateway.sh
test/sharness/t0110-gateway.sh
+2
-2
t0111-gateway-writable.sh
test/sharness/t0111-gateway-writable.sh
+2
-2
dagreader.go
unixfs/io/dagreader.go
+8
-4
没有找到文件。
core/commands/cat.go
浏览文件 @
f5f5700d
...
...
@@ -68,17 +68,12 @@ func cat(node *core.IpfsNode, paths []string) ([]io.Reader, uint64, error) {
return
nil
,
0
,
err
}
nodeLength
,
err
:=
dagnode
.
Size
()
if
err
!=
nil
{
return
nil
,
0
,
err
}
length
+=
nodeLength
read
,
err
:=
uio
.
NewDagReader
(
node
.
Context
(),
dagnode
,
node
.
DAG
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
readers
=
append
(
readers
,
read
)
length
+=
uint64
(
read
.
Size
())
}
return
readers
,
length
,
nil
}
test/sharness/lib/test-lib.sh
浏览文件 @
f5f5700d
...
...
@@ -100,6 +100,30 @@ test_wait_open_tcp_port_10_sec() {
return
1
}
# test_config_set helps us make sure _we really did set_ a config value.
# it sets it and then tests it. This became elaborate because ipfs config
# was setting really weird things and am not sure why.
test_config_set
()
{
# grab flags (like -bool in "ipfs config -bool")
test_cfg_flags
=
""
# unset in case.
test
"$#"
=
3
&&
{
test_cfg_flags
=
$1
;
shift
;
}
test_cfg_key
=
$1
test_cfg_val
=
$2
# when verbose, tell the user what config values are being set
test_cfg_cmd
=
"ipfs config
$test_cfg_flags
\"
$test_cfg_key
\"
\"
$test_cfg_val
\"
"
test
"
$TEST_VERBOSE
"
=
1
&&
echo
"
$test_cfg_cmd
"
# ok try setting the config key/val pair.
ipfs config
$test_cfg_flags
"
$test_cfg_key
"
"
$test_cfg_val
"
echo
"
$test_cfg_val
"
>
cfg_set_expected
ipfs config
"
$test_cfg_key
"
>
cfg_set_actual
test_cmp cfg_set_expected cfg_set_actual
}
test_init_ipfs
()
{
test_expect_success
"ipfs init succeeds"
'
...
...
@@ -107,33 +131,45 @@ test_init_ipfs() {
ipfs init -b=1024 > /dev/null
'
test_expect_success
"prepare config"
'
test_expect_success
"prepare config
-- mounting and bootstrap rm
"
'
mkdir mountdir ipfs ipns &&
ipfs config Mounts.IPFS "$(pwd)/ipfs" &&
ipfs config Mounts.IPNS "$(pwd)/ipns" &&
ipfs bootstrap rm --all
test_config_set Mounts.IPFS "$(pwd)/ipfs" &&
test_config_set Mounts.IPNS "$(pwd)/ipns" &&
ipfs bootstrap rm --all ||
fsh cat "\"$IPFS_PATH/config\""
'
}
test_config_ipfs_gateway_readonly
()
{
test_expect_success
"prepare config -- gateway readonly"
'
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/5002
if
test
"
$1
"
==
""
;
then
echo
"must call with an address, for example:"
echo
'test_config_ipfs_gateway_readonly "/ip4/0.0.0.0/tcp/5002"'
return
1
# todo: find a better way to exit here.
fi
GWAY_ADDR
=
$1
test_expect_success
"prepare config -- gateway address"
'
test_config_set "Addresses.Gateway" "$GWAY_ADDR"
'
}
test_config_ipfs_gateway_writable
()
{
test_config_ipfs_gateway_readonly
$1
test_expect_success
"prepare config -- gateway writable"
'
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/5002 &&
ipfs config -bool Gateway.Writable true
test_config_set -bool Gateway.Writable true ||
fsh cat "\"$IPFS_PATH/config\""
'
}
test_launch_ipfs_daemon
()
{
ADDR_API
=
"/ip4/127.0.0.1/tcp/5001"
ADDR_GWAY
=
`
ipfs config Addresses.Gateway
`
NLINES
=
"2"
# ADDR_GWAY will be set if the test_config_ipfs_gateway_* funcs were called.
if
test
"
$ADDR_GWAY
"
!=
""
;
then
NLINES
=
"3"
fi
...
...
@@ -146,22 +182,23 @@ test_launch_ipfs_daemon() {
# and we make sure there are no errors
test_expect_success
"'ipfs daemon' is ready"
'
IPFS_PID=$! &&
test_wait_output_n_lines_60_sec actual_daemon $NLINES &&
printf "" >empty && test_cmp daemon_err empty ||
test_wait_output_n_lines_60_sec actual_daemon $NLINES ||
fsh cat actual_daemon || fsh cat daemon_err
'
test_expect_success
"'ipfs daemon' output includes API address"
'
cat actual_daemon | grep "API server listening on $ADDR_API" ||
fsh cat actual_daemon ||
fsh "cat actual_daemon | grep \"API server listening on $ADDR_API\""
fsh "cat actual_daemon | grep \"API server listening on $ADDR_API\"" ||
fsh cat daemon_err
'
if
test
"
$ADDR_GWAY
"
!=
""
;
then
test_expect_success
"'ipfs daemon' output includes Gateway address"
'
cat actual_daemon | grep "Gateway server listening on $ADDR_GWAY" ||
fsh cat actual_daemon ||
fsh "cat actual_daemon | grep \"Gateway server listening on $ADDR_GWAY\""
fsh "cat actual_daemon | grep \"Gateway server listening on $ADDR_GWAY\"" ||
fsh cat daemon_err
'
fi
}
...
...
test/sharness/t0021-config.sh
0 → 100755
浏览文件 @
f5f5700d
#!/bin/sh
test_description
=
"Test config command"
.
lib/test-lib.sh
# we use a function so that we can run it both offline + online
test_config_cmd_set
()
{
# flags (like -bool in "ipfs config -bool")
cfg_flags
=
""
# unset in case.
test
"$#"
=
3
&&
{
cfg_flags
=
$1
;
shift
;
}
cfg_key
=
$1
cfg_val
=
$2
test_expect_success
"ipfs config succeeds"
'
ipfs config $cfg_flags "$cfg_key" "$cfg_val"
'
test_expect_success
"ipfs config output looks good"
'
echo "$cfg_val" >expected &&
ipfs config "$cfg_key" >actual &&
test_cmp expected actual
'
# also test our lib function. it should work too.
cfg_key
=
"Lib.
$cfg_key
"
test_expect_success
"test_config_set succeeds"
'
test_config_set $cfg_flags "$cfg_key" "$cfg_val"
'
test_expect_success
"test_config_set value looks good"
'
echo "$cfg_val" >expected &&
ipfs config "$cfg_key" >actual &&
test_cmp expected actual
'
}
test_config_cmd
()
{
test_config_cmd_set
"beep"
"boop"
test_config_cmd_set
"beep1"
"boop2"
test_config_cmd_set
"beep1"
"boop2"
test_config_cmd_set
"-bool"
"beep2"
"true"
test_config_cmd_set
"-bool"
"beep2"
"false"
}
test_init_ipfs
# should work offline
test_config_cmd
# should work online
test_launch_ipfs_daemon
test_config_cmd
test_kill_ipfs_daemon
test_done
test/sharness/t0090-get.sh
浏览文件 @
f5f5700d
...
...
@@ -68,6 +68,7 @@ test_expect_success "ipfs get -a -C output looks good" '
test_cmp expected actual
'
# TODO(mappum)
test_expect_failure
"gzipped tar archive output is valid"
'
tar -zxf "$HASH".tar.gz &&
test_cmp "$HASH" data &&
...
...
@@ -106,7 +107,8 @@ test_expect_success "ipfs get -a -C output looks good (directory)" '
test_cmp expected actual
'
test_expect_success
"gzipped tar archive output is valid (directory)"
'
# TODO(mappum)
test_expect_failure
"gzipped tar archive output is valid (directory)"
'
tar -zxf "$HASH2".tar.gz &&
test_cmp dir/a "$HASH2"/a &&
test_cmp dir/b/c "$HASH2"/b/c &&
...
...
test/sharness/t0110-gateway.sh
浏览文件 @
f5f5700d
...
...
@@ -4,12 +4,12 @@
# MIT Licensed; see the LICENSE file in this repository.
#
test_description
=
"Test HTTP
g
ateway"
test_description
=
"Test HTTP
G
ateway"
.
lib/test-lib.sh
test_init_ipfs
test_config_ipfs_gateway_readonly
test_config_ipfs_gateway_readonly
"/ip4/0.0.0.0/tcp/5002"
test_launch_ipfs_daemon
# TODO check both 5001 and 5002.
...
...
test/sharness/t0111-gateway-writable.sh
浏览文件 @
f5f5700d
...
...
@@ -4,12 +4,12 @@
# MIT Licensed; see the LICENSE file in this repository.
#
test_description
=
"Test HTTP Gateway"
test_description
=
"Test HTTP Gateway
(Writable)
"
.
lib/test-lib.sh
test_init_ipfs
test_config_ipfs_gateway_writable
test_config_ipfs_gateway_writable
"/ip4/0.0.0.0/tcp/5002"
test_launch_ipfs_daemon
test_expect_success
"ipfs daemon listening to TCP port 5002"
'
...
...
unixfs/io/dagreader.go
浏览文件 @
f5f5700d
...
...
@@ -54,7 +54,7 @@ type ReadSeekCloser interface {
// NewDagReader creates a new reader object that reads the data represented by the given
// node, using the passed in DAGService for data retreival
func
NewDagReader
(
ctx
context
.
Context
,
n
*
mdag
.
Node
,
serv
mdag
.
DAGService
)
(
ReadSeekClos
er
,
error
)
{
func
NewDagReader
(
ctx
context
.
Context
,
n
*
mdag
.
Node
,
serv
mdag
.
DAGService
)
(
*
DagRead
er
,
error
)
{
pb
:=
new
(
ftpb
.
Data
)
err
:=
proto
.
Unmarshal
(
n
.
Data
,
pb
)
if
err
!=
nil
{
...
...
@@ -65,6 +65,8 @@ func NewDagReader(ctx context.Context, n *mdag.Node, serv mdag.DAGService) (Read
case
ftpb
.
Data_Directory
:
// Dont allow reading directories
return
nil
,
ErrIsDir
case
ftpb
.
Data_Raw
:
fallthrough
case
ftpb
.
Data_File
:
fctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
promises
:=
serv
.
GetDAG
(
fctx
,
n
)
...
...
@@ -77,9 +79,6 @@ func NewDagReader(ctx context.Context, n *mdag.Node, serv mdag.DAGService) (Read
cancel
:
cancel
,
pbdata
:
pb
,
},
nil
case
ftpb
.
Data_Raw
:
// Raw block will just be a single level, return a byte buffer
return
NewRSNCFromBytes
(
pb
.
GetData
()),
nil
default
:
return
nil
,
ft
.
ErrUnrecognizedType
}
...
...
@@ -123,6 +122,11 @@ func (dr *DagReader) precalcNextBuf() error {
}
}
// Size return the total length of the data from the DAG structured file.
func
(
dr
*
DagReader
)
Size
()
int64
{
return
int64
(
dr
.
pbdata
.
GetFilesize
())
}
// Read reads data from the DAG structured file
func
(
dr
*
DagReader
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
// If no cached buffer, load one
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论