Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
f5f44ab2
提交
f5f44ab2
authored
3月 30, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: remove ctx from ParsePath, split ParseCid
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
15f8fc60
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
60 行增加
和
38 行删除
+60
-38
block.go
core/coreapi/block.go
+9
-5
dag.go
core/coreapi/dag.go
+2
-2
coreapi.go
core/coreapi/interface/coreapi.go
+6
-3
object.go
core/coreapi/object.go
+4
-4
path.go
core/coreapi/path.go
+10
-5
pin.go
core/coreapi/pin.go
+14
-5
pin_test.go
core/coreapi/pin_test.go
+3
-3
unixfs.go
core/coreapi/unixfs.go
+1
-1
unixfs_test.go
core/coreapi/unixfs_test.go
+9
-8
gateway_handler.go
core/corehttp/gateway_handler.go
+2
-2
没有找到文件。
core/coreapi/block.go
浏览文件 @
f5f44ab2
...
...
@@ -65,11 +65,11 @@ func (api *BlockAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Bloc
return
nil
,
err
}
return
api
.
ParseCid
(
b
.
Cid
()),
nil
return
api
.
core
()
.
IpldPath
(
b
.
Cid
()),
nil
}
func
(
api
*
BlockAPI
)
Get
(
ctx
context
.
Context
,
p
coreiface
.
Path
)
(
io
.
Reader
,
error
)
{
rp
,
err
:=
api
.
ResolvePath
(
ctx
,
p
)
rp
,
err
:=
api
.
core
()
.
ResolvePath
(
ctx
,
p
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -83,7 +83,7 @@ func (api *BlockAPI) Get(ctx context.Context, p coreiface.Path) (io.Reader, erro
}
func
(
api
*
BlockAPI
)
Rm
(
ctx
context
.
Context
,
p
coreiface
.
Path
,
opts
...
caopts
.
BlockRmOption
)
error
{
rp
,
err
:=
api
.
ResolvePath
(
ctx
,
p
)
rp
,
err
:=
api
.
core
()
.
ResolvePath
(
ctx
,
p
)
if
err
!=
nil
{
return
err
}
...
...
@@ -121,7 +121,7 @@ func (api *BlockAPI) Rm(ctx context.Context, p coreiface.Path, opts ...caopts.Bl
}
func
(
api
*
BlockAPI
)
Stat
(
ctx
context
.
Context
,
p
coreiface
.
Path
)
(
coreiface
.
BlockStat
,
error
)
{
rp
,
err
:=
api
.
ResolvePath
(
ctx
,
p
)
rp
,
err
:=
api
.
core
()
.
ResolvePath
(
ctx
,
p
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -132,7 +132,7 @@ func (api *BlockAPI) Stat(ctx context.Context, p coreiface.Path) (coreiface.Bloc
}
return
&
BlockStat
{
path
:
api
.
ParseCid
(
b
.
Cid
()),
path
:
api
.
core
()
.
IpldPath
(
b
.
Cid
()),
size
:
len
(
b
.
RawData
()),
},
nil
}
...
...
@@ -144,3 +144,7 @@ func (bs *BlockStat) Size() int {
func
(
bs
*
BlockStat
)
Path
()
coreiface
.
ResolvedPath
{
return
bs
.
path
}
func
(
api
*
BlockAPI
)
core
()
coreiface
.
CoreAPI
{
return
(
*
CoreAPI
)(
api
)
}
core/coreapi/dag.go
浏览文件 @
f5f44ab2
...
...
@@ -44,7 +44,7 @@ func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPut
return
nil
,
err
}
return
api
.
ParseCid
(
nds
[
0
]
.
Cid
()),
nil
return
api
.
core
()
.
IpldPath
(
nds
[
0
]
.
Cid
()),
nil
}
// Get resolves `path` using Unixfs resolver, returns the resolved Node.
...
...
@@ -66,7 +66,7 @@ func (api *DagAPI) Tree(ctx context.Context, p coreiface.Path, opts ...caopts.Da
paths
:=
n
.
Tree
(
""
,
settings
.
Depth
)
out
:=
make
([]
coreiface
.
Path
,
len
(
paths
))
for
n
,
p2
:=
range
paths
{
out
[
n
],
err
=
api
.
ParsePath
(
ctx
,
gopath
.
Join
(
p
.
String
(),
p2
))
out
[
n
],
err
=
api
.
core
()
.
ParsePath
(
gopath
.
Join
(
p
.
String
(),
p2
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
core/coreapi/interface/coreapi.go
浏览文件 @
f5f44ab2
...
...
@@ -40,8 +40,11 @@ type CoreAPI interface {
ResolveNode
(
context
.
Context
,
Path
)
(
ipld
.
Node
,
error
)
// ParsePath parses string path to a Path
ParsePath
(
context
.
Context
,
string
)
(
Path
,
error
)
ParsePath
(
string
)
(
Path
,
error
)
// ParseCid creates new path from the provided CID
ParseCid
(
*
cid
.
Cid
)
ResolvedPath
// IpfsPath creates new /ipfs path from the provided CID
IpfsPath
(
*
cid
.
Cid
)
ResolvedPath
// IpldPath creates new /ipld path from the provided CID
IpldPath
(
*
cid
.
Cid
)
ResolvedPath
}
core/coreapi/object.go
浏览文件 @
f5f44ab2
...
...
@@ -121,7 +121,7 @@ func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Obj
return
nil
,
err
}
return
api
.
ParseCid
(
dagnode
.
Cid
()),
nil
return
api
.
core
()
.
IpfsPath
(
dagnode
.
Cid
()),
nil
}
func
(
api
*
ObjectAPI
)
Get
(
ctx
context
.
Context
,
path
coreiface
.
Path
)
(
ipld
.
Node
,
error
)
{
...
...
@@ -218,7 +218,7 @@ func (api *ObjectAPI) AddLink(ctx context.Context, base coreiface.Path, name str
return
nil
,
err
}
return
api
.
ParseCid
(
nnode
.
Cid
()),
nil
return
api
.
core
()
.
IpfsPath
(
nnode
.
Cid
()),
nil
}
func
(
api
*
ObjectAPI
)
RmLink
(
ctx
context
.
Context
,
base
coreiface
.
Path
,
link
string
)
(
coreiface
.
ResolvedPath
,
error
)
{
...
...
@@ -244,7 +244,7 @@ func (api *ObjectAPI) RmLink(ctx context.Context, base coreiface.Path, link stri
return
nil
,
err
}
return
api
.
ParseCid
(
nnode
.
Cid
()),
nil
return
api
.
core
()
.
IpfsPath
(
nnode
.
Cid
()),
nil
}
func
(
api
*
ObjectAPI
)
AppendData
(
ctx
context
.
Context
,
path
coreiface
.
Path
,
r
io
.
Reader
)
(
coreiface
.
ResolvedPath
,
error
)
{
...
...
@@ -281,7 +281,7 @@ func (api *ObjectAPI) patchData(ctx context.Context, path coreiface.Path, r io.R
return
nil
,
err
}
return
api
.
ParseCid
(
pbnd
.
Cid
()),
nil
return
api
.
core
()
.
IpfsPath
(
pbnd
.
Cid
()),
nil
}
func
(
api
*
ObjectAPI
)
core
()
coreiface
.
CoreAPI
{
...
...
core/coreapi/path.go
浏览文件 @
f5f44ab2
...
...
@@ -26,12 +26,17 @@ type resolvedPath struct {
root
*
cid
.
Cid
}
//
ParseCid parses the path from `c`, ret
runs the parsed path.
func
(
api
*
CoreAPI
)
ParseCid
(
c
*
cid
.
Cid
)
coreiface
.
ResolvedPath
{
return
&
resolvedPath
{
path
:
path
{
ipfspath
.
FromCid
(
c
)},
cid
:
c
,
root
:
c
}
//
IpfsPath parses the path from `c`, re
runs the parsed path.
func
(
api
*
CoreAPI
)
IpfsPath
(
c
*
cid
.
Cid
)
coreiface
.
ResolvedPath
{
return
&
resolvedPath
{
path
:
path
{
ipfspath
.
Path
(
"/ipfs/"
+
c
.
String
()
)},
cid
:
c
,
root
:
c
}
}
// ResolveNode resolves the path `p` using Unixfx resolver, gets and returns the
// IpldPath parses the path from `c`, reruns the parsed path.
func
(
api
*
CoreAPI
)
IpldPath
(
c
*
cid
.
Cid
)
coreiface
.
ResolvedPath
{
return
&
resolvedPath
{
path
:
path
{
ipfspath
.
Path
(
"/ipld/"
+
c
.
String
())},
cid
:
c
,
root
:
c
}
}
// ResolveNode resolves the path `p` using Unixfs resolver, gets and returns the
// resolved Node.
func
(
api
*
CoreAPI
)
ResolveNode
(
ctx
context
.
Context
,
p
coreiface
.
Path
)
(
ipld
.
Node
,
error
)
{
return
resolveNode
(
ctx
,
api
.
node
.
DAG
,
api
.
node
.
Namesys
,
p
)
...
...
@@ -83,7 +88,7 @@ func resolvePath(ctx context.Context, ng ipld.NodeGetter, nsys namesys.NameSyste
}
// ParsePath parses path `p` using ipfspath parser, returns the parsed path.
func
(
api
*
CoreAPI
)
ParsePath
(
ctx
context
.
Context
,
p
string
)
(
coreiface
.
Path
,
error
)
{
func
(
api
*
CoreAPI
)
ParsePath
(
p
string
)
(
coreiface
.
Path
,
error
)
{
pp
,
err
:=
ipfspath
.
ParsePath
(
p
)
if
err
!=
nil
{
return
nil
,
err
...
...
core/coreapi/pin.go
浏览文件 @
f5f44ab2
...
...
@@ -24,7 +24,12 @@ func (api *PinAPI) Add(ctx context.Context, p coreiface.Path, opts ...caopts.Pin
defer
api
.
node
.
Blockstore
.
PinLock
()
.
Unlock
()
_
,
err
=
corerepo
.
Pin
(
api
.
node
,
ctx
,
[]
string
{
p
.
String
()},
settings
.
Recursive
)
rp
,
err
:=
api
.
core
()
.
ResolvePath
(
ctx
,
p
)
if
err
!=
nil
{
return
err
}
_
,
err
=
corerepo
.
Pin
(
api
.
node
,
ctx
,
[]
string
{
rp
.
Cid
()
.
String
()},
settings
.
Recursive
)
if
err
!=
nil
{
return
err
}
...
...
@@ -62,12 +67,12 @@ func (api *PinAPI) Update(ctx context.Context, from coreiface.Path, to coreiface
return
err
}
fp
,
err
:=
api
.
ResolvePath
(
ctx
,
from
)
fp
,
err
:=
api
.
core
()
.
ResolvePath
(
ctx
,
from
)
if
err
!=
nil
{
return
err
}
tp
,
err
:=
api
.
ResolvePath
(
ctx
,
to
)
tp
,
err
:=
api
.
core
()
.
ResolvePath
(
ctx
,
to
)
if
err
!=
nil
{
return
err
}
...
...
@@ -120,7 +125,7 @@ func (api *PinAPI) Verify(ctx context.Context) (<-chan coreiface.PinStatus, erro
links
,
err
:=
getLinks
(
ctx
,
root
)
if
err
!=
nil
{
status
:=
&
pinStatus
{
ok
:
false
,
cid
:
root
}
status
.
badNodes
=
[]
coreiface
.
BadPinNode
{
&
badNode
{
path
:
api
.
ParseCid
(
root
),
err
:
err
}}
status
.
badNodes
=
[]
coreiface
.
BadPinNode
{
&
badNode
{
path
:
api
.
core
()
.
IpldPath
(
root
),
err
:
err
}}
visited
[
key
]
=
status
return
status
}
...
...
@@ -170,7 +175,7 @@ func (api *PinAPI) pinLsAll(typeStr string, ctx context.Context) ([]coreiface.Pi
for
_
,
c
:=
range
keyList
{
keys
[
c
.
String
()]
=
&
pinInfo
{
pinType
:
typeStr
,
path
:
api
.
ParseCid
(
c
),
path
:
api
.
core
()
.
IpldPath
(
c
),
}
}
}
...
...
@@ -199,3 +204,7 @@ func (api *PinAPI) pinLsAll(typeStr string, ctx context.Context) ([]coreiface.Pi
return
out
,
nil
}
func
(
api
*
PinAPI
)
core
()
coreiface
.
CoreAPI
{
return
(
*
CoreAPI
)(
api
)
}
core/coreapi/pin_test.go
浏览文件 @
f5f44ab2
...
...
@@ -52,7 +52,7 @@ func TestPinSimple(t *testing.T) {
t
.
Errorf
(
"unexpected pin list len: %d"
,
len
(
list
))
}
if
list
[
0
]
.
Path
()
.
String
()
!=
p
.
String
()
{
if
list
[
0
]
.
Path
()
.
Cid
()
.
String
()
!=
p
.
Cid
()
.
String
()
{
t
.
Error
(
"paths don't match"
)
}
...
...
@@ -156,7 +156,7 @@ func TestPinRecursive(t *testing.T) {
t
.
Errorf
(
"unexpected pin list len: %d"
,
len
(
list
))
}
if
list
[
0
]
.
Path
()
.
String
()
!=
p0
.
String
()
{
if
list
[
0
]
.
Path
()
.
Cid
()
.
String
()
!=
p0
.
Cid
()
.
String
()
{
t
.
Error
(
"unexpected path"
)
}
...
...
@@ -195,7 +195,7 @@ func TestPinRecursive(t *testing.T) {
t
.
Fatalf
(
"unexpected badNodes len"
)
}
if
r
.
BadNodes
()[
0
]
.
Path
()
.
String
()
!=
p0
.
String
()
{
if
r
.
BadNodes
()[
0
]
.
Path
()
.
Cid
()
.
String
()
!=
p0
.
Cid
()
.
String
()
{
t
.
Error
(
"unexpected badNode path"
)
}
...
...
core/coreapi/unixfs.go
浏览文件 @
f5f44ab2
...
...
@@ -25,7 +25,7 @@ func (api *UnixfsAPI) Add(ctx context.Context, r io.Reader) (coreiface.ResolvedP
if
err
!=
nil
{
return
nil
,
err
}
return
api
.
core
()
.
ParseCid
(
c
),
nil
return
api
.
core
()
.
IpfsPath
(
c
),
nil
}
// Cat returns the data contained by an IPFS or IPNS object(s) at path `p`.
...
...
core/coreapi/unixfs_test.go
浏览文件 @
f5f44ab2
...
...
@@ -12,6 +12,7 @@ import (
core
"github.com/ipfs/go-ipfs/core"
coreapi
"github.com/ipfs/go-ipfs/core/coreapi"
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
options
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
coreunix
"github.com/ipfs/go-ipfs/core/coreunix"
keystore
"github.com/ipfs/go-ipfs/keystore"
mdag
"github.com/ipfs/go-ipfs/merkledag"
...
...
@@ -213,18 +214,18 @@ func TestCatDir(t *testing.T) {
if
err
!=
nil
{
t
.
Error
(
err
)
}
p
:=
api
.
ParseCid
(
edir
.
Cid
())
p
:=
api
.
IpfsPath
(
edir
.
Cid
())
emptyDir
,
err
:=
api
.
Object
()
.
New
(
ctx
,
api
.
Object
()
.
With
Type
(
"unixfs-dir"
))
emptyDir
,
err
:=
api
.
Object
()
.
New
(
ctx
,
options
.
Object
.
Type
(
"unixfs-dir"
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
p
.
String
()
!=
api
.
ParseCid
(
emptyDir
.
Cid
())
.
String
()
{
if
p
.
String
()
!=
api
.
IpfsPath
(
emptyDir
.
Cid
())
.
String
()
{
t
.
Fatalf
(
"expected path %s, got: %s"
,
emptyDir
.
Cid
(),
p
.
String
())
}
_
,
err
=
api
.
Unixfs
()
.
Cat
(
ctx
,
api
.
ParseCid
(
emptyDir
.
Cid
()))
_
,
err
=
api
.
Unixfs
()
.
Cat
(
ctx
,
api
.
IpfsPath
(
emptyDir
.
Cid
()))
if
err
!=
coreiface
.
ErrIsDir
{
t
.
Fatalf
(
"expected ErrIsDir, got: %s"
,
err
)
}
...
...
@@ -243,7 +244,7 @@ func TestCatNonUnixfs(t *testing.T) {
t
.
Error
(
err
)
}
_
,
err
=
api
.
Unixfs
()
.
Cat
(
ctx
,
api
.
ParseCid
(
nd
.
Cid
()))
_
,
err
=
api
.
Unixfs
()
.
Cat
(
ctx
,
api
.
IpfsPath
(
nd
.
Cid
()))
if
!
strings
.
Contains
(
err
.
Error
(),
"proto: required field"
)
{
t
.
Fatalf
(
"expected protobuf error, got: %s"
,
err
)
}
...
...
@@ -318,12 +319,12 @@ func TestLsEmptyDir(t *testing.T) {
t
.
Error
(
err
)
}
emptyDir
,
err
:=
api
.
Object
()
.
New
(
ctx
,
api
.
Object
()
.
With
Type
(
"unixfs-dir"
))
emptyDir
,
err
:=
api
.
Object
()
.
New
(
ctx
,
options
.
Object
.
Type
(
"unixfs-dir"
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
links
,
err
:=
api
.
Unixfs
()
.
Ls
(
ctx
,
api
.
ParseCid
(
emptyDir
.
Cid
()))
links
,
err
:=
api
.
Unixfs
()
.
Ls
(
ctx
,
api
.
IpfsPath
(
emptyDir
.
Cid
()))
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -351,7 +352,7 @@ func TestLsNonUnixfs(t *testing.T) {
t
.
Error
(
err
)
}
links
,
err
:=
api
.
Unixfs
()
.
Ls
(
ctx
,
api
.
ParseCid
(
nd
.
Cid
()))
links
,
err
:=
api
.
Unixfs
()
.
Ls
(
ctx
,
api
.
IpfsPath
(
nd
.
Cid
()))
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
core/corehttp/gateway_handler.go
浏览文件 @
f5f44ab2
...
...
@@ -159,7 +159,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
ipnsHostname
=
true
}
parsedPath
,
err
:=
i
.
api
.
ParsePath
(
ctx
,
urlPath
)
parsedPath
,
err
:=
i
.
api
.
ParsePath
(
urlPath
)
if
err
!=
nil
{
webError
(
w
,
"invalid ipfs path"
,
err
,
http
.
StatusBadRequest
)
return
...
...
@@ -287,7 +287,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
return
}
dr
,
err
:=
i
.
api
.
Unixfs
()
.
Cat
(
ctx
,
i
.
api
.
ParseCid
(
ixnd
.
Cid
()))
dr
,
err
:=
i
.
api
.
Unixfs
()
.
Cat
(
ctx
,
i
.
api
.
IpfsPath
(
ixnd
.
Cid
()))
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论