Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
34b1313d
提交
34b1313d
authored
10月 09, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi unixfs: remove Cat, use sessions
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
dd4d8bb2
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
53 行增加
和
50 行删除
+53
-50
cat.go
core/commands/cat.go
+29
-8
unixfs.go
core/coreapi/interface/unixfs.go
+0
-4
unixfs.go
core/coreapi/unixfs.go
+2
-19
unixfs_test.go
core/coreapi/unixfs_test.go
+13
-8
gateway_handler.go
core/corehttp/gateway_handler.go
+5
-7
ipfs_test.go
fuse/readonly/ipfs_test.go
+1
-1
addcat_test.go
test/integration/addcat_test.go
+1
-1
bench_cat_test.go
test/integration/bench_cat_test.go
+1
-1
three_legged_cat_test.go
test/integration/three_legged_cat_test.go
+1
-1
没有找到文件。
core/commands/cat.go
浏览文件 @
34b1313d
...
...
@@ -10,6 +10,7 @@ import (
"github.com/ipfs/go-ipfs/core/coreapi/interface"
cmds
"gx/ipfs/QmRRovo1DE6i5cMjCbf19mQCSuszF6SKwdZNUMS7MtBnH1/go-ipfs-cmds"
"gx/ipfs/QmZMWMvWMVKCbHetJ4RgndbuEF1io2UpUxwQwtNjtYPzSC/go-ipfs-files"
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
)
...
...
@@ -123,6 +124,12 @@ var CatCmd = &cmds.Command{
},
}
type
catFile
interface
{
files
.
SizeFile
io
.
Seeker
}
func
cat
(
ctx
context
.
Context
,
api
iface
.
CoreAPI
,
paths
[]
string
,
offset
int64
,
max
int64
)
([]
io
.
Reader
,
uint64
,
error
)
{
readers
:=
make
([]
io
.
Reader
,
0
,
len
(
paths
))
length
:=
uint64
(
0
)
...
...
@@ -135,32 +142,46 @@ func cat(ctx context.Context, api iface.CoreAPI, paths []string, offset int64, m
return
nil
,
0
,
err
}
read
,
err
:=
api
.
Unixfs
()
.
Cat
(
ctx
,
fpath
)
f
,
err
:=
api
.
Unixfs
()
.
Get
(
ctx
,
fpath
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
file
:=
f
.
(
catFile
)
fsize
,
err
:=
file
.
Size
()
if
err
!=
nil
{
return
nil
,
0
,
err
}
if
offset
>
int64
(
read
.
Size
())
{
offset
=
offset
-
int64
(
read
.
Size
())
if
offset
>
fsize
{
offset
=
offset
-
fsize
continue
}
count
,
err
:=
read
.
Seek
(
offset
,
io
.
SeekStart
)
count
,
err
:=
file
.
Seek
(
offset
,
io
.
SeekStart
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
offset
=
0
size
:=
uint64
(
read
.
Size
()
-
uint64
(
count
))
fsize
,
err
=
file
.
Size
()
if
err
!=
nil
{
return
nil
,
0
,
err
}
size
:=
uint64
(
fsize
-
count
)
length
+=
size
if
max
>
0
&&
length
>=
uint64
(
max
)
{
var
r
io
.
Reader
=
read
var
r
io
.
Reader
=
file
if
overshoot
:=
int64
(
length
-
uint64
(
max
));
overshoot
!=
0
{
r
=
io
.
LimitReader
(
read
,
int64
(
size
)
-
overshoot
)
r
=
io
.
LimitReader
(
file
,
int64
(
size
)
-
overshoot
)
length
=
uint64
(
max
)
}
readers
=
append
(
readers
,
r
)
break
}
readers
=
append
(
readers
,
read
)
readers
=
append
(
readers
,
file
)
}
return
readers
,
length
,
nil
}
core/coreapi/interface/unixfs.go
浏览文件 @
34b1313d
...
...
@@ -31,10 +31,6 @@ type UnixfsAPI interface {
// to operations performed on the returned file
Get
(
context
.
Context
,
Path
)
(
files
.
File
,
error
)
// Cat returns a reader for the file
// TODO: Remove in favour of Get (if we use Get on a file we still have reader directly, so..)
Cat
(
context
.
Context
,
Path
)
(
Reader
,
error
)
// Ls returns the list of links in a directory
Ls
(
context
.
Context
,
Path
)
([]
*
ipld
.
Link
,
error
)
}
core/coreapi/unixfs.go
浏览文件 @
34b1313d
...
...
@@ -139,25 +139,8 @@ func (api *UnixfsAPI) Get(ctx context.Context, p coreiface.Path) (files.File, er
return
nil
,
err
}
return
newUnixfsFile
(
ctx
,
api
.
node
.
DAG
,
nd
,
""
,
nil
)
}
// Cat returns the data contained by an IPFS or IPNS object(s) at path `p`.
func
(
api
*
UnixfsAPI
)
Cat
(
ctx
context
.
Context
,
p
coreiface
.
Path
)
(
coreiface
.
Reader
,
error
)
{
dget
:=
api
.
node
.
DAG
// TODO: use a session here once routing perf issues are resolved
dagnode
,
err
:=
api
.
core
()
.
ResolveNode
(
ctx
,
p
)
if
err
!=
nil
{
return
nil
,
err
}
r
,
err
:=
uio
.
NewDagReader
(
ctx
,
dagnode
,
dget
)
if
err
==
uio
.
ErrIsDir
{
return
nil
,
coreiface
.
ErrIsDir
}
else
if
err
!=
nil
{
return
nil
,
err
}
return
r
,
nil
ses
:=
dag
.
NewReadOnlyDagService
(
dag
.
NewSession
(
ctx
,
api
.
node
.
DAG
))
return
newUnixfsFile
(
ctx
,
ses
,
nd
,
""
,
nil
)
}
// Ls returns the contents of an IPFS or IPNS object(s) at path p, with the format:
...
...
core/coreapi/unixfs_test.go
浏览文件 @
34b1313d
...
...
@@ -623,7 +623,7 @@ func TestAddHashOnly(t *testing.T) {
}
}
func
Test
Ca
tEmptyFile
(
t
*
testing
.
T
)
{
func
Test
Ge
tEmptyFile
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
node
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
...
...
@@ -640,7 +640,7 @@ func TestCatEmptyFile(t *testing.T) {
t
.
Fatal
(
err
)
}
r
,
err
:=
api
.
Unixfs
()
.
Ca
t
(
ctx
,
emptyFilePath
)
r
,
err
:=
api
.
Unixfs
()
.
Ge
t
(
ctx
,
emptyFilePath
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -655,7 +655,7 @@ func TestCatEmptyFile(t *testing.T) {
}
}
func
Test
Ca
tDir
(
t
*
testing
.
T
)
{
func
Test
Ge
tDir
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
node
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
...
...
@@ -677,13 +677,18 @@ func TestCatDir(t *testing.T) {
t
.
Fatalf
(
"expected path %s, got: %s"
,
emptyDir
.
Cid
(),
p
.
String
())
}
_
,
err
=
api
.
Unixfs
()
.
Cat
(
ctx
,
coreiface
.
IpfsPath
(
emptyDir
.
Cid
()))
if
err
!=
coreiface
.
ErrIsDir
{
r
,
err
:=
api
.
Unixfs
()
.
Get
(
ctx
,
coreiface
.
IpfsPath
(
emptyDir
.
Cid
()))
if
err
!=
nil
{
t
.
Error
(
err
)
}
_
,
err
=
r
.
Read
(
make
([]
byte
,
2
))
if
err
!=
files
.
ErrNotReader
{
t
.
Fatalf
(
"expected ErrIsDir, got: %s"
,
err
)
}
}
func
Test
Ca
tNonUnixfs
(
t
*
testing
.
T
)
{
func
Test
Ge
tNonUnixfs
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
node
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
...
...
@@ -696,7 +701,7 @@ func TestCatNonUnixfs(t *testing.T) {
t
.
Error
(
err
)
}
_
,
err
=
api
.
Unixfs
()
.
Ca
t
(
ctx
,
coreiface
.
IpfsPath
(
nd
.
Cid
()))
_
,
err
=
api
.
Unixfs
()
.
Ge
t
(
ctx
,
coreiface
.
IpfsPath
(
nd
.
Cid
()))
if
!
strings
.
Contains
(
err
.
Error
(),
"proto: required field"
)
{
t
.
Fatalf
(
"expected protobuf error, got: %s"
,
err
)
}
...
...
@@ -713,7 +718,7 @@ func TestCatOffline(t *testing.T) {
if
err
!=
nil
{
t
.
Error
(
err
)
}
_
,
err
=
api
.
Unixfs
()
.
Ca
t
(
ctx
,
p
)
_
,
err
=
api
.
Unixfs
()
.
Ge
t
(
ctx
,
p
)
if
err
!=
coreiface
.
ErrOffline
{
t
.
Fatalf
(
"expected ErrOffline, got: %s"
,
err
)
}
...
...
core/corehttp/gateway_handler.go
浏览文件 @
34b1313d
...
...
@@ -178,14 +178,12 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
return
}
dr
,
err
:=
i
.
api
.
Unixfs
()
.
Ca
t
(
ctx
,
resolvedPath
)
dir
:=
false
dr
,
err
:=
i
.
api
.
Unixfs
()
.
Ge
t
(
ctx
,
resolvedPath
)
dir
:=
dr
.
IsDirectory
()
switch
err
{
case
nil
:
// Cat() worked
defer
dr
.
Close
()
case
coreiface
.
ErrIsDir
:
dir
=
true
default
:
webError
(
w
,
"ipfs cat "
+
escapedURLPath
,
err
,
http
.
StatusNotFound
)
return
...
...
@@ -270,7 +268,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
}
else
{
name
=
getFilename
(
urlPath
)
}
i
.
serveFile
(
w
,
r
,
name
,
modtime
,
dr
)
i
.
serveFile
(
w
,
r
,
name
,
modtime
,
dr
.
(
io
.
ReadSeeker
)
)
return
}
...
...
@@ -297,7 +295,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
return
}
dr
,
err
:=
i
.
api
.
Unixfs
()
.
Ca
t
(
ctx
,
coreiface
.
IpfsPath
(
ixnd
.
Cid
()))
dr
,
err
:=
i
.
api
.
Unixfs
()
.
Ge
t
(
ctx
,
coreiface
.
IpfsPath
(
ixnd
.
Cid
()))
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
...
...
@@ -305,7 +303,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
defer
dr
.
Close
()
// write to request
http
.
ServeContent
(
w
,
r
,
"index.html"
,
modtime
,
dr
)
http
.
ServeContent
(
w
,
r
,
"index.html"
,
modtime
,
dr
.
(
io
.
ReadSeeker
)
)
return
default
:
internalWebError
(
w
,
err
)
...
...
fuse/readonly/ipfs_test.go
浏览文件 @
34b1313d
...
...
@@ -175,7 +175,7 @@ func TestIpfsStressRead(t *testing.T) {
errs
<-
err
}
read
,
err
:=
api
.
Unixfs
()
.
Ca
t
(
nd
.
Context
(),
item
)
read
,
err
:=
api
.
Unixfs
()
.
Ge
t
(
nd
.
Context
(),
item
)
if
err
!=
nil
{
errs
<-
err
}
...
...
test/integration/addcat_test.go
浏览文件 @
34b1313d
...
...
@@ -147,7 +147,7 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
return
err
}
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Ca
t
(
ctx
,
ap
)
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Ge
t
(
ctx
,
ap
)
if
err
!=
nil
{
return
err
}
...
...
test/integration/bench_cat_test.go
浏览文件 @
34b1313d
...
...
@@ -94,7 +94,7 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
}
b
.
StartTimer
()
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Ca
t
(
ctx
,
ap
)
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Ge
t
(
ctx
,
ap
)
if
err
!=
nil
{
return
err
}
...
...
test/integration/three_legged_cat_test.go
浏览文件 @
34b1313d
...
...
@@ -126,7 +126,7 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
return
err
}
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Ca
t
(
ctx
,
ap
)
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Ge
t
(
ctx
,
ap
)
if
err
!=
nil
{
return
err
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论