Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
f9f3c6a5
提交
f9f3c6a5
authored
7月 20, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make offline commands respect timeout
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
60830079
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
41 行增加
和
31 行删除
+41
-31
main.go
cmd/ipfs/main.go
+7
-0
handler.go
commands/http/handler.go
+1
-21
request.go
commands/request.go
+23
-0
pin.go
core/commands/pin.go
+7
-2
pinning.go
core/corerepo/pinning.go
+2
-7
t0081-repo-pinning.sh
test/sharness/t0081-repo-pinning.sh
+1
-1
没有找到文件。
cmd/ipfs/main.go
浏览文件 @
f9f3c6a5
...
...
@@ -335,6 +335,13 @@ func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd
}
else
{
log
.
Debug
(
"Executing command locally"
)
ctx
,
err
:=
cmds
.
GetContext
(
ctx
,
req
)
if
err
!=
nil
{
return
nil
,
err
}
req
.
Context
()
.
Context
=
ctx
// Okay!!!!! NOW we can call the command.
res
=
root
.
Call
(
req
)
...
...
commands/http/handler.go
浏览文件 @
f9f3c6a5
...
...
@@ -7,10 +7,8 @@ import (
"net/http"
"strconv"
"strings"
"time"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/rs/cors"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
cmds
"github.com/ipfs/go-ipfs/commands"
u
"github.com/ipfs/go-ipfs/util"
...
...
@@ -108,31 +106,13 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
tout
,
found
,
err
:=
req
.
Option
(
"timeout"
)
.
String
(
)
ctx
,
err
:=
cmds
.
GetContext
(
node
.
Context
(),
req
)
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"error parsing timeout option: %s"
,
err
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
var
ctx
context
.
Context
if
found
{
duration
,
err
:=
time
.
ParseDuration
(
tout
)
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"error parsing timeout option: %s"
,
err
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
tctx
,
cancel
:=
context
.
WithTimeout
(
node
.
Context
(),
duration
)
defer
cancel
()
ctx
=
tctx
}
else
{
cctx
,
cancel
:=
context
.
WithCancel
(
node
.
Context
())
defer
cancel
()
ctx
=
cctx
}
//ps: take note of the name clash - commands.Context != context.Context
cmdctx
:=
i
.
ctx
cmdctx
.
Context
=
ctx
...
...
commands/request.go
浏览文件 @
f9f3c6a5
...
...
@@ -7,6 +7,7 @@ import (
"os"
"reflect"
"strconv"
"time"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/ipfs/go-ipfs/commands/files"
...
...
@@ -297,3 +298,25 @@ func NewRequest(path []string, opts OptMap, args []string, file files.File, cmd
return
req
,
nil
}
func
GetContext
(
base
context
.
Context
,
req
Request
)
(
context
.
Context
,
error
)
{
tout
,
found
,
err
:=
req
.
Option
(
"timeout"
)
.
String
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error parsing timeout option: %s"
,
err
)
}
var
ctx
context
.
Context
if
found
{
duration
,
err
:=
time
.
ParseDuration
(
tout
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error parsing timeout option: %s"
,
err
)
}
tctx
,
_
:=
context
.
WithTimeout
(
base
,
duration
)
ctx
=
tctx
}
else
{
cctx
,
_
:=
context
.
WithCancel
(
base
)
ctx
=
cctx
}
return
ctx
,
nil
}
core/commands/pin.go
浏览文件 @
f9f3c6a5
...
...
@@ -60,7 +60,12 @@ on disk.
recursive
=
false
}
added
,
err
:=
corerepo
.
Pin
(
n
,
req
.
Arguments
(),
recursive
)
go
func
()
{
<-
req
.
Context
()
.
Context
.
Done
()
log
.
Error
(
"CONTEXT IS OVER!"
)
}()
added
,
err
:=
corerepo
.
Pin
(
n
,
req
.
Context
()
.
Context
,
req
.
Arguments
(),
recursive
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
...
...
@@ -125,7 +130,7 @@ collected if needed.
recursive
=
false
// default
}
removed
,
err
:=
corerepo
.
Unpin
(
n
,
req
.
Arguments
(),
recursive
)
removed
,
err
:=
corerepo
.
Unpin
(
n
,
req
.
Context
()
.
Context
,
req
.
Arguments
(),
recursive
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
...
...
core/corerepo/pinning.go
浏览文件 @
f9f3c6a5
...
...
@@ -25,10 +25,7 @@ import (
path
"github.com/ipfs/go-ipfs/path"
)
func
Pin
(
n
*
core
.
IpfsNode
,
paths
[]
string
,
recursive
bool
)
([]
key
.
Key
,
error
)
{
// TODO(cryptix): do we want a ctx as first param for (Un)Pin() as well, just like core.Resolve?
ctx
:=
n
.
Context
()
func
Pin
(
n
*
core
.
IpfsNode
,
ctx
context
.
Context
,
paths
[]
string
,
recursive
bool
)
([]
key
.
Key
,
error
)
{
dagnodes
:=
make
([]
*
merkledag
.
Node
,
0
)
for
_
,
fpath
:=
range
paths
{
dagnode
,
err
:=
core
.
Resolve
(
ctx
,
n
,
path
.
Path
(
fpath
))
...
...
@@ -62,9 +59,7 @@ func Pin(n *core.IpfsNode, paths []string, recursive bool) ([]key.Key, error) {
return
out
,
nil
}
func
Unpin
(
n
*
core
.
IpfsNode
,
paths
[]
string
,
recursive
bool
)
([]
key
.
Key
,
error
)
{
// TODO(cryptix): do we want a ctx as first param for (Un)Pin() as well, just like core.Resolve?
ctx
:=
n
.
Context
()
func
Unpin
(
n
*
core
.
IpfsNode
,
ctx
context
.
Context
,
paths
[]
string
,
recursive
bool
)
([]
key
.
Key
,
error
)
{
dagnodes
:=
make
([]
*
merkledag
.
Node
,
0
)
for
_
,
fpath
:=
range
paths
{
...
...
test/sharness/t0081-repo-pinning.sh
浏览文件 @
f9f3c6a5
...
...
@@ -242,7 +242,7 @@ test_expect_success "some are no longer there" '
test_expect_success
"recursive pin fails without objects"
'
ipfs pin rm "$HASH_DIR1" &&
test_must_fail ipfs pin add -r "$HASH_DIR1" 2>err_expected8 &&
test_must_fail ipfs pin add -r "$HASH_DIR1"
--timeout=500ms
2>err_expected8 &&
grep "context deadline exceeded" err_expected8
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论