Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
2f999d4b
提交
2f999d4b
authored
6月 13, 2017
作者:
Jeromy Johnson
提交者:
GitHub
6月 13, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3975 from Stebalien/fix/3974
pinning + pathresolver: fix pinning/unpinning of sharded directories
上级
8ec0814a
8c78d407
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
46 行增加
和
13 行删除
+46
-13
pin.go
core/commands/pin.go
+14
-3
pinning.go
core/corerepo/pinning.go
+15
-3
pathresolver.go
core/pathresolver.go
+7
-7
t0250-files-api.sh
test/sharness/t0250-files-api.sh
+10
-0
没有找到文件。
core/commands/pin.go
浏览文件 @
2f999d4b
...
...
@@ -12,6 +12,7 @@ import (
dag
"github.com/ipfs/go-ipfs/merkledag"
path
"github.com/ipfs/go-ipfs/path"
pin
"github.com/ipfs/go-ipfs/pin"
uio
"github.com/ipfs/go-ipfs/unixfs/io"
context
"context"
u
"gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
...
...
@@ -377,13 +378,18 @@ new pin and removing the old one.
return
}
fromc
,
err
:=
core
.
ResolveToCid
(
req
.
Context
(),
n
,
from
)
r
:=
&
path
.
Resolver
{
DAG
:
n
.
DAG
,
ResolveOnce
:
uio
.
ResolveUnixfsOnce
,
}
fromc
,
err
:=
core
.
ResolveToCid
(
req
.
Context
(),
n
.
Namesys
,
r
,
from
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
toc
,
err
:=
core
.
ResolveToCid
(
req
.
Context
(),
n
,
to
)
toc
,
err
:=
core
.
ResolveToCid
(
req
.
Context
(),
n
.
Namesys
,
r
,
to
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
...
...
@@ -486,13 +492,18 @@ func pinLsKeys(args []string, typeStr string, ctx context.Context, n *core.IpfsN
keys
:=
make
(
map
[
string
]
RefKeyObject
)
r
:=
&
path
.
Resolver
{
DAG
:
n
.
DAG
,
ResolveOnce
:
uio
.
ResolveUnixfsOnce
,
}
for
_
,
p
:=
range
args
{
pth
,
err
:=
path
.
ParsePath
(
p
)
if
err
!=
nil
{
return
nil
,
err
}
c
,
err
:=
core
.
ResolveToCid
(
ctx
,
n
,
pth
)
c
,
err
:=
core
.
ResolveToCid
(
ctx
,
n
.
Namesys
,
r
,
pth
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
core/corerepo/pinning.go
浏览文件 @
2f999d4b
...
...
@@ -19,6 +19,7 @@ import (
"github.com/ipfs/go-ipfs/core"
path
"github.com/ipfs/go-ipfs/path"
uio
"github.com/ipfs/go-ipfs/unixfs/io"
cid
"gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
node
"gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
...
...
@@ -26,13 +27,19 @@ import (
func
Pin
(
n
*
core
.
IpfsNode
,
ctx
context
.
Context
,
paths
[]
string
,
recursive
bool
)
([]
*
cid
.
Cid
,
error
)
{
dagnodes
:=
make
([]
node
.
Node
,
0
)
r
:=
&
path
.
Resolver
{
DAG
:
n
.
DAG
,
ResolveOnce
:
uio
.
ResolveUnixfsOnce
,
}
for
_
,
fpath
:=
range
paths
{
p
,
err
:=
path
.
ParsePath
(
fpath
)
if
err
!=
nil
{
return
nil
,
err
}
dagnode
,
err
:=
core
.
Resolve
(
ctx
,
n
.
Namesys
,
n
.
Resolve
r
,
p
)
dagnode
,
err
:=
core
.
Resolve
(
ctx
,
n
.
Namesys
,
r
,
p
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"pin: %s"
,
err
)
}
...
...
@@ -61,15 +68,20 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool)
}
func
Unpin
(
n
*
core
.
IpfsNode
,
ctx
context
.
Context
,
paths
[]
string
,
recursive
bool
)
([]
*
cid
.
Cid
,
error
)
{
var
unpinned
[]
*
cid
.
Cid
r
:=
&
path
.
Resolver
{
DAG
:
n
.
DAG
,
ResolveOnce
:
uio
.
ResolveUnixfsOnce
,
}
for
_
,
p
:=
range
paths
{
p
,
err
:=
path
.
ParsePath
(
p
)
if
err
!=
nil
{
return
nil
,
err
}
k
,
err
:=
core
.
ResolveToCid
(
ctx
,
n
,
p
)
k
,
err
:=
core
.
ResolveToCid
(
ctx
,
n
.
Namesys
,
r
,
p
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
core/pathresolver.go
浏览文件 @
2f999d4b
...
...
@@ -57,14 +57,14 @@ func Resolve(ctx context.Context, nsys namesys.NameSystem, r *path.Resolver, p p
return
r
.
ResolvePath
(
ctx
,
p
)
}
// ResolveTo
Key resolves a path to a key
.
// ResolveTo
Cid resolves a path to a cid
.
//
// It first checks if the path is already in the form of just a
key (<key
> or
// /ipfs/<
key
>) and returns immediately if so. Otherwise, it falls back onto
// It first checks if the path is already in the form of just a
cid (<cid
> or
// /ipfs/<
cid
>) and returns immediately if so. Otherwise, it falls back onto
// Resolve to perform resolution of the dagnode being referenced.
func
ResolveToCid
(
ctx
context
.
Context
,
n
*
IpfsNode
,
p
path
.
Path
)
(
*
cid
.
Cid
,
error
)
{
func
ResolveToCid
(
ctx
context
.
Context
,
n
sys
namesys
.
NameSystem
,
r
*
path
.
Resolver
,
p
path
.
Path
)
(
*
cid
.
Cid
,
error
)
{
// If the path is simply a
key
, parse and return it. Parsed paths are already
// If the path is simply a
cid
, parse and return it. Parsed paths are already
// normalized (read: prepended with /ipfs/ if needed), so segment[1] should
// always be the key.
if
p
.
IsJustAKey
()
{
...
...
@@ -77,12 +77,12 @@ func ResolveToCid(ctx context.Context, n *IpfsNode, p path.Path) (*cid.Cid, erro
if
err
!=
nil
{
return
nil
,
err
}
dagnode
,
err
:=
Resolve
(
ctx
,
n
.
Namesys
,
n
.
Resolve
r
,
head
)
dagnode
,
err
:=
Resolve
(
ctx
,
n
sys
,
r
,
head
)
if
err
!=
nil
{
return
nil
,
err
}
// Extract and return the
key
of the link to the target dag node.
// Extract and return the
cid
of the link to the target dag node.
link
,
_
,
err
:=
dagnode
.
ResolveLink
([]
string
{
tail
})
if
err
!=
nil
{
return
nil
,
err
...
...
test/sharness/t0250-files-api.sh
浏览文件 @
2f999d4b
...
...
@@ -72,6 +72,16 @@ test_sharding() {
test_cmp file_out file_exp
'
test_expect_success
"can pin a file from sharded directory"
'
ipfs files stat --hash /foo/file42 > pin_file_hash &&
ipfs pin add < pin_file_hash > pin_hash
'
test_expect_success
"can unpin a file from sharded directory"
'
read -r _ HASH _ < pin_hash &&
ipfs pin rm $HASH
'
test_expect_success
"output object was really sharded"
'
ipfs files stat --hash /foo > expected_foo_hash &&
echo QmPkwLJTYZRGPJ8Lazr9qPdrLmswPtUjaDbEpmR9jEh1se > actual_foo_hash &&
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论