Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
2c71c548
提交
2c71c548
authored
5月 22, 2015
作者:
Travis Person
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Named error for `no components`
Update the previous `invalid path` error to match the error returned from `SplitAbsPath`.
上级
d96246c6
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
16 行增加
和
8 行删除
+16
-8
pathresolver.go
core/pathresolver.go
+1
-2
pathresolver_test.go
core/pathresolver_test.go
+9
-5
resolver.go
path/resolver.go
+6
-1
没有找到文件。
core/pathresolver.go
浏览文件 @
2c71c548
...
...
@@ -3,7 +3,6 @@ package core
import
(
"errors"
"strings"
"fmt"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
...
...
@@ -32,7 +31,7 @@ func Resolve(ctx context.Context, n *IpfsNode, p path.Path) (*merkledag.Node, er
seg
:=
p
.
Segments
()
if
len
(
seg
)
<
2
||
seg
[
1
]
==
""
{
// just "/<protocol/>" without further segments
return
nil
,
fmt
.
Errorf
(
"invalid path: %s"
,
string
(
p
))
return
nil
,
path
.
ErrNoComponents
}
extensions
:=
seg
[
2
:
]
...
...
core/pathresolver_test.go
浏览文件 @
2c71c548
...
...
@@ -4,18 +4,22 @@ import (
"testing"
path
"github.com/ipfs/go-ipfs/path"
"strings"
)
func
TestResolve
InvalidPath
(
t
*
testing
.
T
)
{
func
TestResolve
NoComponents
(
t
*
testing
.
T
)
{
n
,
err
:=
NewMockNode
()
if
n
==
nil
||
err
!=
nil
{
t
.
Fatal
(
"Should have constructed."
,
err
)
t
.
Fatal
(
"Should have constructed a mock node"
,
err
)
}
_
,
err
=
Resolve
(
n
.
Context
(),
n
,
path
.
Path
(
"/ipns/"
))
if
err
!=
path
.
ErrNoComponents
{
t
.
Fatal
(
"Should error with no components (/ipns/)."
,
err
)
}
_
,
err
=
Resolve
(
n
.
Context
(),
n
,
path
.
Path
(
"/ipfs/"
))
if
!
strings
.
HasPrefix
(
err
.
Error
(),
"invalid path"
)
{
t
.
Fatal
(
"Should
get invalid path
."
,
err
)
if
err
!=
path
.
ErrNoComponents
{
t
.
Fatal
(
"Should
error with no components (/ipfs/)
."
,
err
)
}
}
path/resolver.go
浏览文件 @
2c71c548
...
...
@@ -4,6 +4,7 @@ package path
import
(
"fmt"
"time"
"errors"
mh
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
...
...
@@ -14,6 +15,10 @@ import (
var
log
=
u
.
Logger
(
"path"
)
// Paths after a protocol must contain at least one component
var
ErrNoComponents
=
errors
.
New
(
"path must contain at least one component"
)
// ErrNoLink is returned when a link is not found in a path
type
ErrNoLink
struct
{
name
string
...
...
@@ -43,7 +48,7 @@ func SplitAbsPath(fpath Path) (mh.Multihash, []string, error) {
// if nothing, bail.
if
len
(
parts
)
==
0
{
return
nil
,
nil
,
fmt
.
Errorf
(
"ipfs path must contain at least one component"
)
return
nil
,
nil
,
ErrNoComponents
}
// first element in the path is a b58 hash (for now)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论