Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
f338520a
提交
f338520a
authored
3月 02, 2017
作者:
Kevin Atkinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gc: add option to stream errors
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
上级
401d1565
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
53 行增加
和
22 行删除
+53
-22
repo.go
core/commands/repo.go
+46
-18
gc.go
core/corerepo/gc.go
+0
-4
t0087-repo-robust-gc.sh
test/sharness/t0087-repo-robust-gc.sh
+7
-0
没有找到文件。
core/commands/repo.go
浏览文件 @
f338520a
...
...
@@ -40,6 +40,11 @@ var RepoCmd = &cmds.Command{
},
}
type
GcResult
struct
{
Key
*
cid
.
Cid
Error
string
`json:",omitempty"`
}
var
repoGcCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Perform a garbage collection sweep on the repo."
,
...
...
@@ -51,6 +56,7 @@ order to reclaim hard disk space.
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"quiet"
,
"q"
,
"Write minimal output."
)
.
Default
(
false
),
cmds
.
BoolOption
(
"stream-errors"
,
"Stream errors."
)
.
Default
(
false
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
...
...
@@ -59,22 +65,41 @@ order to reclaim hard disk space.
return
}
streamErrors
,
_
,
_
:=
res
.
Request
()
.
Option
(
"stream-errors"
)
.
Bool
()
gcOutChan
:=
corerepo
.
GarbageCollectAsync
(
n
,
req
.
Context
())
outChan
:=
make
(
chan
interface
{},
len
(
gcOutChan
))
outChan
:=
make
(
chan
interface
{},
cap
(
gcOutChan
))
res
.
SetOutput
((
<-
chan
interface
{})(
outChan
))
go
func
()
{
defer
close
(
outChan
)
err
:=
corerepo
.
CollectResult
(
req
.
Context
(),
gcOutChan
,
func
(
k
*
cid
.
Cid
)
{
outChan
<-
&
corerepo
.
KeyRemoved
{
k
}
})
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
unreportedError
:=
false
var
lastErr
error
if
streamErrors
{
for
res
:=
range
gcOutChan
{
if
unreportedError
{
outChan
<-
&
GcResult
{
Error
:
lastErr
.
Error
()}
unreportedError
=
false
}
if
res
.
Error
!=
nil
{
lastErr
=
res
.
Error
unreportedError
=
true
}
else
{
outChan
<-
&
GcResult
{
Key
:
res
.
KeyRemoved
}
}
}
}
else
{
lastErr
=
corerepo
.
CollectResult
(
req
.
Context
(),
gcOutChan
,
func
(
k
*
cid
.
Cid
)
{
outChan
<-
&
GcResult
{
Key
:
k
}
})
}
if
lastErr
!=
nil
{
res
.
SetError
(
lastErr
,
cmds
.
ErrNormal
)
}
}()
},
Type
:
corerepo
.
KeyRemoved
{},
Type
:
GcResult
{},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
outChan
,
ok
:=
res
.
Output
()
.
(
<-
chan
interface
{})
...
...
@@ -87,26 +112,29 @@ order to reclaim hard disk space.
return
nil
,
err
}
marshal
:=
func
(
v
interface
{})
(
io
.
Reader
,
error
)
{
obj
,
ok
:=
v
.
(
*
corerepo
.
KeyRemoved
)
for
v
:=
range
outChan
{
obj
,
ok
:=
v
.
(
*
GcResult
)
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
buf
:=
new
(
bytes
.
Buffer
)
if
obj
.
Error
!=
""
{
fmt
.
Fprintf
(
res
.
Stderr
(),
"Error: %s
\n
"
,
obj
.
Error
)
continue
}
if
quiet
{
buf
=
bytes
.
NewBufferString
(
obj
.
Key
.
String
()
+
"
\n
"
)
fmt
.
Fprintf
(
res
.
Stdout
(),
"%s
\n
"
,
obj
.
Key
.
String
()
)
}
else
{
buf
=
bytes
.
NewBufferString
(
fmt
.
Sprintf
(
"removed %s
\n
"
,
obj
.
Key
))
fmt
.
Fprintf
(
res
.
Stdout
(),
"removed %s
\n
"
,
obj
.
Key
.
String
(
))
}
return
buf
,
nil
}
return
&
cmds
.
ChannelMarshaler
{
Channel
:
outChan
,
Marshaler
:
marshal
,
Res
:
res
,
}
,
nil
if
res
.
Error
()
!=
nil
{
return
nil
,
res
.
Error
()
}
return
nil
,
nil
},
},
}
...
...
core/corerepo/gc.go
浏览文件 @
f338520a
...
...
@@ -20,10 +20,6 @@ var log = logging.Logger("corerepo")
var
ErrMaxStorageExceeded
=
errors
.
New
(
"Maximum storage limit exceeded. Maybe unpin some files?"
)
type
KeyRemoved
struct
{
Key
*
cid
.
Cid
}
type
GC
struct
{
Node
*
core
.
IpfsNode
Repo
repo
.
Repo
...
...
test/sharness/t0087-repo-robust-gc.sh
浏览文件 @
f338520a
...
...
@@ -134,6 +134,13 @@ test_gc_robust_part2() {
grep -q "aborted" repo_gc_out
'
test_expect_success
"'ipfs repo gc --stream-errors' should abort and report each error separately"
'
test_must_fail ipfs repo gc --stream-errors 2>&1 | tee repo_gc_out &&
grep -q "Error: could not retrieve links for $LEAF1" repo_gc_out &&
grep -q "Error: could not retrieve links for $LEAF2" repo_gc_out &&
grep -q "Error: garbage collection aborted" repo_gc_out
'
test_expect_success
"unpin 1MB file"
'
ipfs pin rm $HASH2
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论