Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
7ee61943
提交
7ee61943
authored
3月 30, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: path.Mutable
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
f5f44ab2
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
63 行增加
和
4 行删除
+63
-4
path.go
core/coreapi/interface/path.go
+13
-1
path.go
core/coreapi/path.go
+16
-3
path_test.go
core/coreapi/path_test.go
+34
-0
没有找到文件。
core/coreapi/interface/path.go
浏览文件 @
7ee61943
...
@@ -6,13 +6,25 @@ import (
...
@@ -6,13 +6,25 @@ import (
// Path is a generic wrapper for paths used in the API. A path can be resolved
// Path is a generic wrapper for paths used in the API. A path can be resolved
// to a CID using one of Resolve functions in the API.
// to a CID using one of Resolve functions in the API.
// TODO: figure out/explain namespaces
//
// Paths must be prefixed with a valid prefix:
//
// * /ipfs - Immutable unixfs path (files)
// * /ipld - Immutable ipld path (data)
// * /ipns - Mutable names. Usually resolves to one of the immutable paths
//TODO: /local (MFS)
type
Path
interface
{
type
Path
interface
{
// String returns the path as a string.
// String returns the path as a string.
String
()
string
String
()
string
// Namespace returns the first component of the path
// Namespace returns the first component of the path
Namespace
()
string
Namespace
()
string
// Mutable returns false if the data pointed to by this path in guaranteed
// to not change.
//
// Note that resolved mutable path can be immutable.
Mutable
()
bool
}
}
// ResolvedPath is a resolved Path
// ResolvedPath is a resolved Path
...
...
core/coreapi/path.go
浏览文件 @
7ee61943
...
@@ -97,7 +97,10 @@ func (api *CoreAPI) ParsePath(p string) (coreiface.Path, error) {
...
@@ -97,7 +97,10 @@ func (api *CoreAPI) ParsePath(p string) (coreiface.Path, error) {
return
&
path
{
path
:
pp
},
nil
return
&
path
{
path
:
pp
},
nil
}
}
func
(
p
*
path
)
String
()
string
{
return
p
.
path
.
String
()
}
func
(
p
*
path
)
String
()
string
{
return
p
.
path
.
String
()
}
func
(
p
*
path
)
Namespace
()
string
{
func
(
p
*
path
)
Namespace
()
string
{
if
len
(
p
.
path
.
Segments
())
<
1
{
if
len
(
p
.
path
.
Segments
())
<
1
{
return
""
return
""
...
@@ -105,5 +108,15 @@ func (p *path) Namespace() string {
...
@@ -105,5 +108,15 @@ func (p *path) Namespace() string {
return
p
.
path
.
Segments
()[
0
]
return
p
.
path
.
Segments
()[
0
]
}
}
func
(
p
*
resolvedPath
)
Cid
()
*
cid
.
Cid
{
return
p
.
cid
}
func
(
p
*
path
)
Mutable
()
bool
{
func
(
p
*
resolvedPath
)
Root
()
*
cid
.
Cid
{
return
p
.
root
}
//TODO: MFS: check for /local
return
p
.
Namespace
()
==
"ipns"
}
func
(
p
*
resolvedPath
)
Cid
()
*
cid
.
Cid
{
return
p
.
cid
}
func
(
p
*
resolvedPath
)
Root
()
*
cid
.
Cid
{
return
p
.
root
}
core/coreapi/path_test.go
0 → 100644
浏览文件 @
7ee61943
package
coreapi_test
import
(
"context"
"strings"
"testing"
)
func
TestMutablePath
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// get self /ipns path
keys
,
err
:=
api
.
Key
()
.
List
(
ctx
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
keys
[
0
]
.
Path
()
.
Mutable
()
{
t
.
Error
(
"expected self /ipns path to be mutable"
)
}
blk
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`foo`
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
blk
.
Mutable
()
{
t
.
Error
(
"expected /ipld path to be immutable"
)
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论