Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
7a08cf9c
提交
7a08cf9c
authored
12月 15, 2018
作者:
Overbool
提交者:
Steven Allen
1月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cmds/pin: modify test
License: MIT Signed-off-by:
Overbool
<
overbool.xu@gmail.com
>
上级
99feecfd
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
31 行增加
和
63 行删除
+31
-63
pin.go
core/commands/pin.go
+30
-59
pin.go
core/coreapi/interface/options/pin.go
+0
-1
pin.go
core/coreapi/pin.go
+0
-2
pinning.go
core/corerepo/pinning.go
+0
-0
t0080-repo.sh
test/sharness/t0080-repo.sh
+1
-1
没有找到文件。
core/commands/pin.go
浏览文件 @
7a08cf9c
...
@@ -7,22 +7,22 @@ import (
...
@@ -7,22 +7,22 @@ import (
"os"
"os"
"time"
"time"
core
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core"
cmdenv
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
e
"github.com/ipfs/go-ipfs/core/commands/e"
"github.com/ipfs/go-ipfs/core/commands/e"
"github.com/ipfs/go-ipfs/core/coreapi/interface"
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
iface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
options
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
"github.com/ipfs/go-ipfs/pin"
pin
"github.com/ipfs/go-ipfs/pin"
cid
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
bserv
"gx/ipfs/QmVKQHuzni68SWByzJgBUCwHvvr4TWiXfutNWWwpZpp4rE/go-blockservice"
bserv
"gx/ipfs/QmVKQHuzni68SWByzJgBUCwHvvr4TWiXfutNWWwpZpp4rE/go-blockservice"
cmds
"gx/ipfs/QmWGm4AbZEbnmdgVTza52MSNpEmBdFVqzmAysRbjrRyGbH/go-ipfs-cmds"
"gx/ipfs/QmWGm4AbZEbnmdgVTza52MSNpEmBdFVqzmAysRbjrRyGbH/go-ipfs-cmds"
"gx/ipfs/QmYMQuypUbgsdNHmuCBSUJV6wdQVsBHRivNAp3efHJwZJD/go-verifcid"
"gx/ipfs/QmYMQuypUbgsdNHmuCBSUJV6wdQVsBHRivNAp3efHJwZJD/go-verifcid"
offline
"gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
"gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
dag
"gx/ipfs/Qmb2UEG2TAeVrEJSjqsZF7Y2he7wRDkrdt6c3bECxwZf4k/go-merkledag"
dag
"gx/ipfs/Qmb2UEG2TAeVrEJSjqsZF7Y2he7wRDkrdt6c3bECxwZf4k/go-merkledag"
cidenc
"gx/ipfs/QmdPQx9fvN5ExVwMhRmh7YpCQJzJrFhd1AjVBwJmRMFJeX/go-cidutil/cidenc"
"gx/ipfs/QmdPQx9fvN5ExVwMhRmh7YpCQJzJrFhd1AjVBwJmRMFJeX/go-cidutil/cidenc"
cmdkit
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
)
)
var
PinCmd
=
&
cmds
.
Command
{
var
PinCmd
=
&
cmds
.
Command
{
...
@@ -68,18 +68,11 @@ var addPinCmd = &cmds.Command{
...
@@ -68,18 +68,11 @@ var addPinCmd = &cmds.Command{
},
},
Type
:
AddPinOutput
{},
Type
:
AddPinOutput
{},
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
error
{
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
error
{
n
,
err
:=
cmdenv
.
GetNode
(
env
)
if
err
!=
nil
{
return
err
}
api
,
err
:=
cmdenv
.
GetApi
(
env
,
req
)
api
,
err
:=
cmdenv
.
GetApi
(
env
,
req
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
defer
n
.
Blockstore
.
PinLock
()
.
Unlock
()
// set recursive flag
// set recursive flag
recursive
,
_
:=
req
.
Options
[
pinRecursiveOptionName
]
.
(
bool
)
recursive
,
_
:=
req
.
Options
[
pinRecursiveOptionName
]
.
(
bool
)
showProgress
,
_
:=
req
.
Options
[
pinProgressOptionName
]
.
(
bool
)
showProgress
,
_
:=
req
.
Options
[
pinProgressOptionName
]
.
(
bool
)
...
@@ -88,8 +81,13 @@ var addPinCmd = &cmds.Command{
...
@@ -88,8 +81,13 @@ var addPinCmd = &cmds.Command{
return
err
return
err
}
}
enc
,
err
:=
cmdenv
.
GetCidEncoder
(
req
)
if
err
!=
nil
{
return
err
}
if
!
showProgress
{
if
!
showProgress
{
added
,
err
:=
pinAddMany
(
req
.
Context
,
api
,
req
.
Arguments
,
recursive
)
added
,
err
:=
pinAddMany
(
req
.
Context
,
api
,
enc
,
req
.
Arguments
,
recursive
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -107,7 +105,7 @@ var addPinCmd = &cmds.Command{
...
@@ -107,7 +105,7 @@ var addPinCmd = &cmds.Command{
ch
:=
make
(
chan
pinResult
,
1
)
ch
:=
make
(
chan
pinResult
,
1
)
go
func
()
{
go
func
()
{
added
,
err
:=
pinAddMany
(
req
.
Context
,
api
,
req
.
Arguments
,
recursive
)
added
,
err
:=
pinAddMany
(
ctx
,
api
,
enc
,
req
.
Arguments
,
recursive
)
ch
<-
pinResult
{
pins
:
added
,
err
:
err
}
ch
<-
pinResult
{
pins
:
added
,
err
:
err
}
}()
}()
...
@@ -183,7 +181,7 @@ var addPinCmd = &cmds.Command{
...
@@ -183,7 +181,7 @@ var addPinCmd = &cmds.Command{
},
},
}
}
func
pinAddMany
(
ctx
context
.
Context
,
api
coreiface
.
CoreAPI
,
paths
[]
string
,
recursive
bool
)
([]
string
,
error
)
{
func
pinAddMany
(
ctx
context
.
Context
,
api
coreiface
.
CoreAPI
,
enc
cidenc
.
Encoder
,
paths
[]
string
,
recursive
bool
)
([]
string
,
error
)
{
added
:=
make
([]
string
,
len
(
paths
))
added
:=
make
([]
string
,
len
(
paths
))
for
i
,
b
:=
range
paths
{
for
i
,
b
:=
range
paths
{
p
,
err
:=
coreiface
.
ParsePath
(
b
)
p
,
err
:=
coreiface
.
ParsePath
(
b
)
...
@@ -196,10 +194,10 @@ func pinAddMany(ctx context.Context, api coreiface.CoreAPI, paths []string, recu
...
@@ -196,10 +194,10 @@ func pinAddMany(ctx context.Context, api coreiface.CoreAPI, paths []string, recu
return
nil
,
err
return
nil
,
err
}
}
if
err
:=
api
.
Pin
()
.
Add
(
ctx
,
p
,
options
.
Pin
.
Recursive
(
recursive
));
err
!=
nil
{
if
err
:=
api
.
Pin
()
.
Add
(
ctx
,
r
p
,
options
.
Pin
.
Recursive
(
recursive
));
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
added
[
i
]
=
rp
.
Cid
()
.
String
(
)
added
[
i
]
=
enc
.
Encode
(
rp
.
Cid
()
)
}
}
return
added
,
nil
return
added
,
nil
...
@@ -239,6 +237,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
...
@@ -239,6 +237,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
return
err
return
err
}
}
pins
:=
make
([]
string
,
0
,
len
(
req
.
Arguments
))
for
_
,
b
:=
range
req
.
Arguments
{
for
_
,
b
:=
range
req
.
Arguments
{
p
,
err
:=
coreiface
.
ParsePath
(
b
)
p
,
err
:=
coreiface
.
ParsePath
(
b
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -250,51 +249,23 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
...
@@ -250,51 +249,23 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
return
err
return
err
}
}
id
:=
enc
.
Encode
(
rp
.
Cid
())
pins
=
append
(
pins
,
id
)
if
err
:=
api
.
Pin
()
.
Rm
(
req
.
Context
,
rp
,
options
.
Pin
.
RmRecursive
(
recursive
));
err
!=
nil
{
if
err
:=
api
.
Pin
()
.
Rm
(
req
.
Context
,
rp
,
options
.
Pin
.
RmRecursive
(
recursive
));
err
!=
nil
{
if
err
:=
res
.
Emit
(
&
PinOutput
{
Pins
:
[]
string
{
rp
.
Cid
()
.
String
()},
Error
:
err
.
Error
(),
});
err
!=
nil
{
return
err
}
continue
}
if
err
:=
res
.
Emit
(
&
PinOutput
{
Pins
:
[]
string
{
rp
.
Cid
()
.
String
()},
});
err
!=
nil
{
return
err
return
err
}
}
}
}
return
nil
return
cmds
.
EmitOnce
(
res
,
&
PinOutput
{
pins
})
},
},
PostRun
:
cmds
.
PostRunMap
{
Encoders
:
cmds
.
EncoderMap
{
cmds
.
CLI
:
func
(
res
cmds
.
Response
,
re
cmds
.
ResponseEmitter
)
error
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
PinOutput
)
error
{
failed
:=
false
for
_
,
k
:=
range
out
.
Pins
{
for
{
fmt
.
Fprintf
(
w
,
"unpinned %s
\n
"
,
k
)
out
,
err
:=
res
.
Next
()
if
err
==
io
.
EOF
{
break
}
else
if
err
!=
nil
{
return
err
}
r
:=
out
.
(
*
PinOutput
)
if
r
.
Pins
==
nil
&&
r
.
Error
!=
""
{
return
fmt
.
Errorf
(
"aborted: %s"
,
r
.
Error
)
}
else
if
r
.
Error
!=
""
{
failed
=
true
fmt
.
Fprintf
(
os
.
Stderr
,
"cannot unpin %s: %s
\n
"
,
r
.
Pins
[
0
],
r
.
Error
)
}
else
{
fmt
.
Fprintf
(
os
.
Stdout
,
"unpinned %s
\n
"
,
r
.
Pins
[
0
])
}
}
}
if
failed
{
return
fmt
.
Errorf
(
"some hash not unpinned"
)
}
return
nil
return
nil
},
}
)
,
},
},
}
}
...
...
core/coreapi/interface/options/pin.go
浏览文件 @
7a08cf9c
...
@@ -11,7 +11,6 @@ type PinLsSettings struct {
...
@@ -11,7 +11,6 @@ type PinLsSettings struct {
// PinRmSettings represents the settings of pin rm command
// PinRmSettings represents the settings of pin rm command
type
PinRmSettings
struct
{
type
PinRmSettings
struct
{
Recursive
bool
Recursive
bool
Force
bool
}
}
type
PinUpdateSettings
struct
{
type
PinUpdateSettings
struct
{
...
...
core/coreapi/pin.go
浏览文件 @
7a08cf9c
...
@@ -6,13 +6,11 @@ import (
...
@@ -6,13 +6,11 @@ import (
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
caopts
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
caopts
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
corerepo
"github.com/ipfs/go-ipfs/core/corerepo"
bserv
"gx/ipfs/QmVKQHuzni68SWByzJgBUCwHvvr4TWiXfutNWWwpZpp4rE/go-blockservice"
bserv
"gx/ipfs/QmVKQHuzni68SWByzJgBUCwHvvr4TWiXfutNWWwpZpp4rE/go-blockservice"
merkledag
"gx/ipfs/Qmb2UEG2TAeVrEJSjqsZF7Y2he7wRDkrdt6c3bECxwZf4k/go-merkledag"
merkledag
"gx/ipfs/Qmb2UEG2TAeVrEJSjqsZF7Y2he7wRDkrdt6c3bECxwZf4k/go-merkledag"
cid
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
cid
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
offline
"gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
offline
"gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
merkledag
"gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
)
)
type
PinAPI
CoreAPI
type
PinAPI
CoreAPI
...
...
core/corerepo/pinning.go
deleted
100644 → 0
浏览文件 @
99feecfd
test/sharness/t0080-repo.sh
浏览文件 @
7a08cf9c
...
@@ -93,7 +93,7 @@ test_expect_success "pinning directly should fail now" '
...
@@ -93,7 +93,7 @@ test_expect_success "pinning directly should fail now" '
'
'
test_expect_success
"'ipfs pin rm -r=false <hash>' should fail"
'
test_expect_success
"'ipfs pin rm -r=false <hash>' should fail"
'
echo "Error: $HASH is pinned recursively" >expected4
&&
echo "Error: $HASH is pinned recursively" >expected4
test_must_fail ipfs pin rm -r=false "$HASH" 2>actual4 &&
test_must_fail ipfs pin rm -r=false "$HASH" 2>actual4 &&
test_cmp expected4 actual4
test_cmp expected4 actual4
'
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论