Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
743f3edc
提交
743f3edc
authored
11月 24, 2015
作者:
rht
提交者:
Jeromy
1月 12, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
strings.Split -> path.SplitList
License: MIT Signed-off-by:
rht
<
rhtbot@gmail.com
>
上级
ffd85923
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
48 行增加
和
44 行删除
+48
-44
parse.go
commands/http/parse.go
+11
-9
dht.go
core/commands/dht.go
+1
-2
files.go
core/commands/files/files.go
+1
-2
gateway_handler.go
core/corehttp/gateway_handler.go
+1
-1
utils.go
merkledag/utils/utils.go
+5
-5
utils_test.go
merkledag/utils/utils_test.go
+3
-3
mfs_test.go
mfs/mfs_test.go
+10
-10
ops.go
mfs/ops.go
+2
-2
path.go
path/path.go
+4
-0
selection.go
routing/record/selection.go
+2
-2
validation.go
routing/record/validation.go
+3
-3
format.go
tar/format.go
+1
-1
ipfsaddr.go
util/ipfsaddr/ipfsaddr.go
+2
-2
ipfsaddr_test.go
util/ipfsaddr/ipfsaddr_test.go
+2
-2
没有找到文件。
commands/http/parse.go
浏览文件 @
743f3edc
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
cmds
"github.com/ipfs/go-ipfs/commands"
cmds
"github.com/ipfs/go-ipfs/commands"
files
"github.com/ipfs/go-ipfs/commands/files"
files
"github.com/ipfs/go-ipfs/commands/files"
path
"github.com/ipfs/go-ipfs/path"
)
)
// Parse parses the data in a http.Request and returns a command Request object
// Parse parses the data in a http.Request and returns a command Request object
...
@@ -16,32 +17,33 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
...
@@ -16,32 +17,33 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
if
!
strings
.
HasPrefix
(
r
.
URL
.
Path
,
ApiPath
)
{
if
!
strings
.
HasPrefix
(
r
.
URL
.
Path
,
ApiPath
)
{
return
nil
,
errors
.
New
(
"Unexpected path prefix"
)
return
nil
,
errors
.
New
(
"Unexpected path prefix"
)
}
}
p
ath
:=
strings
.
Split
(
strings
.
TrimPrefix
(
r
.
URL
.
Path
,
ApiPath
+
"/"
),
"/"
)
p
th
:=
path
.
SplitList
(
strings
.
TrimPrefix
(
r
.
URL
.
Path
,
ApiPath
+
"/"
)
)
stringArgs
:=
make
([]
string
,
0
)
stringArgs
:=
make
([]
string
,
0
)
if
err
:=
apiVersionMatches
(
r
);
err
!=
nil
{
if
err
:=
apiVersionMatches
(
r
);
err
!=
nil
{
if
p
a
th
[
0
]
!=
"version"
{
// compatibility with previous version check
if
pth
[
0
]
!=
"version"
{
// compatibility with previous version check
return
nil
,
err
return
nil
,
err
}
}
}
}
cmd
,
err
:=
root
.
Get
(
p
ath
[
:
len
(
pa
th
)
-
1
])
cmd
,
err
:=
root
.
Get
(
p
th
[
:
len
(
p
th
)
-
1
])
if
err
!=
nil
{
if
err
!=
nil
{
// 404 if there is no command at that path
// 404 if there is no command at that path
return
nil
,
ErrNotFound
return
nil
,
ErrNotFound
}
}
if
sub
:=
cmd
.
Subcommand
(
p
ath
[
len
(
pa
th
)
-
1
]);
sub
==
nil
{
if
sub
:=
cmd
.
Subcommand
(
p
th
[
len
(
p
th
)
-
1
]);
sub
==
nil
{
if
len
(
p
a
th
)
<=
1
{
if
len
(
pth
)
<=
1
{
return
nil
,
ErrNotFound
return
nil
,
ErrNotFound
}
}
// if the last string in the path isn't a subcommand, use it as an argument
// if the last string in the path isn't a subcommand, use it as an argument
// e.g. /objects/Qabc12345 (we are passing "Qabc12345" to the "objects" command)
// e.g. /objects/Qabc12345 (we are passing "Qabc12345" to the "objects" command)
stringArgs
=
append
(
stringArgs
,
path
[
len
(
path
)
-
1
])
stringArgs
=
append
(
stringArgs
,
pth
[
len
(
pth
)
-
1
])
path
=
path
[
:
len
(
path
)
-
1
]
pth
=
pth
[
:
len
(
pth
)
-
1
]
}
else
{
}
else
{
cmd
=
sub
cmd
=
sub
}
}
...
@@ -93,7 +95,7 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
...
@@ -93,7 +95,7 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
}
}
}
}
optDefs
,
err
:=
root
.
GetOptions
(
p
a
th
)
optDefs
,
err
:=
root
.
GetOptions
(
pth
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -116,7 +118,7 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
...
@@ -116,7 +118,7 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
return
nil
,
fmt
.
Errorf
(
"File argument '%s' is required"
,
requiredFile
)
return
nil
,
fmt
.
Errorf
(
"File argument '%s' is required"
,
requiredFile
)
}
}
req
,
err
:=
cmds
.
NewRequest
(
p
a
th
,
opts
,
args
,
f
,
cmd
,
optDefs
)
req
,
err
:=
cmds
.
NewRequest
(
pth
,
opts
,
args
,
f
,
cmd
,
optDefs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
core/commands/dht.go
浏览文件 @
743f3edc
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"io"
"io"
"strings"
"time"
"time"
key
"github.com/ipfs/go-ipfs/blocks/key"
key
"github.com/ipfs/go-ipfs/blocks/key"
...
@@ -600,7 +599,7 @@ PutValue will store the given key value pair in the dht.
...
@@ -600,7 +599,7 @@ PutValue will store the given key value pair in the dht.
}
}
func
escapeDhtKey
(
s
string
)
(
key
.
Key
,
error
)
{
func
escapeDhtKey
(
s
string
)
(
key
.
Key
,
error
)
{
parts
:=
strings
.
Split
(
s
,
"/"
)
parts
:=
path
.
SplitList
(
s
)
switch
len
(
parts
)
{
switch
len
(
parts
)
{
case
1
:
case
1
:
return
key
.
B58KeyDecode
(
s
),
nil
return
key
.
B58KeyDecode
(
s
),
nil
...
...
core/commands/files/files.go
浏览文件 @
743f3edc
...
@@ -245,8 +245,7 @@ Examples:
...
@@ -245,8 +245,7 @@ Examples:
res
.
SetOutput
(
&
FilesLsOutput
{
listing
})
res
.
SetOutput
(
&
FilesLsOutput
{
listing
})
return
return
case
*
mfs
.
File
:
case
*
mfs
.
File
:
parts
:=
strings
.
Split
(
path
,
"/"
)
_
,
name
:=
gopath
.
Split
(
path
)
name
:=
parts
[
len
(
parts
)
-
1
]
out
:=
&
FilesLsOutput
{[]
mfs
.
NodeListing
{
mfs
.
NodeListing
{
Name
:
name
,
Type
:
1
}}}
out
:=
&
FilesLsOutput
{[]
mfs
.
NodeListing
{
mfs
.
NodeListing
{
Name
:
name
,
Type
:
1
}}}
res
.
SetOutput
(
out
)
res
.
SetOutput
(
out
)
return
return
...
...
core/corehttp/gateway_handler.go
浏览文件 @
743f3edc
...
@@ -246,7 +246,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
...
@@ -246,7 +246,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
var
backLink
string
=
prefix
+
urlPath
var
backLink
string
=
prefix
+
urlPath
// don't go further up than /ipfs/$hash/
// don't go further up than /ipfs/$hash/
pathSplit
:=
strings
.
Split
(
backLink
,
"/"
)
pathSplit
:=
path
.
SplitList
(
backLink
)
switch
{
switch
{
// keep backlink
// keep backlink
case
len
(
pathSplit
)
==
3
:
// url: /ipfs/$hash
case
len
(
pathSplit
)
==
3
:
// url: /ipfs/$hash
...
...
merkledag/utils/utils.go
浏览文件 @
743f3edc
...
@@ -2,7 +2,6 @@ package dagutils
...
@@ -2,7 +2,6 @@ package dagutils
import
(
import
(
"errors"
"errors"
"strings"
ds
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
ds
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
syncds
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
syncds
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
...
@@ -12,6 +11,7 @@ import (
...
@@ -12,6 +11,7 @@ import (
bserv
"github.com/ipfs/go-ipfs/blockservice"
bserv
"github.com/ipfs/go-ipfs/blockservice"
offline
"github.com/ipfs/go-ipfs/exchange/offline"
offline
"github.com/ipfs/go-ipfs/exchange/offline"
dag
"github.com/ipfs/go-ipfs/merkledag"
dag
"github.com/ipfs/go-ipfs/merkledag"
path
"github.com/ipfs/go-ipfs/path"
)
)
type
Editor
struct
{
type
Editor
struct
{
...
@@ -76,8 +76,8 @@ func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname s
...
@@ -76,8 +76,8 @@ func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname s
return
root
,
nil
return
root
,
nil
}
}
func
(
e
*
Editor
)
InsertNodeAtPath
(
ctx
context
.
Context
,
p
a
th
string
,
toinsert
*
dag
.
Node
,
create
func
()
*
dag
.
Node
)
error
{
func
(
e
*
Editor
)
InsertNodeAtPath
(
ctx
context
.
Context
,
pth
string
,
toinsert
*
dag
.
Node
,
create
func
()
*
dag
.
Node
)
error
{
splpath
:=
strings
.
Split
(
path
,
"/"
)
splpath
:=
path
.
SplitList
(
pth
)
nd
,
err
:=
e
.
insertNodeAtPath
(
ctx
,
e
.
root
,
splpath
,
toinsert
,
create
)
nd
,
err
:=
e
.
insertNodeAtPath
(
ctx
,
e
.
root
,
splpath
,
toinsert
,
create
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -130,8 +130,8 @@ func (e *Editor) insertNodeAtPath(ctx context.Context, root *dag.Node, path []st
...
@@ -130,8 +130,8 @@ func (e *Editor) insertNodeAtPath(ctx context.Context, root *dag.Node, path []st
return
root
,
nil
return
root
,
nil
}
}
func
(
e
*
Editor
)
RmLink
(
ctx
context
.
Context
,
p
a
th
string
)
error
{
func
(
e
*
Editor
)
RmLink
(
ctx
context
.
Context
,
pth
string
)
error
{
splpath
:=
strings
.
Split
(
path
,
"/"
)
splpath
:=
path
.
SplitList
(
pth
)
nd
,
err
:=
e
.
rmLink
(
ctx
,
e
.
root
,
splpath
)
nd
,
err
:=
e
.
rmLink
(
ctx
,
e
.
root
,
splpath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
merkledag/utils/utils_test.go
浏览文件 @
743f3edc
package
dagutils
package
dagutils
import
(
import
(
"strings"
"testing"
"testing"
key
"github.com/ipfs/go-ipfs/blocks/key"
key
"github.com/ipfs/go-ipfs/blocks/key"
dag
"github.com/ipfs/go-ipfs/merkledag"
dag
"github.com/ipfs/go-ipfs/merkledag"
mdtest
"github.com/ipfs/go-ipfs/merkledag/test"
mdtest
"github.com/ipfs/go-ipfs/merkledag/test"
path
"github.com/ipfs/go-ipfs/path"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
)
)
...
@@ -43,8 +43,8 @@ func TestAddLink(t *testing.T) {
...
@@ -43,8 +43,8 @@ func TestAddLink(t *testing.T) {
}
}
}
}
func
assertNodeAtPath
(
t
*
testing
.
T
,
ds
dag
.
DAGService
,
root
*
dag
.
Node
,
p
a
th
string
,
exp
key
.
Key
)
{
func
assertNodeAtPath
(
t
*
testing
.
T
,
ds
dag
.
DAGService
,
root
*
dag
.
Node
,
pth
string
,
exp
key
.
Key
)
{
parts
:=
strings
.
Split
(
path
,
"/"
)
parts
:=
path
.
SplitList
(
pth
)
cur
:=
root
cur
:=
root
for
_
,
e
:=
range
parts
{
for
_
,
e
:=
range
parts
{
nxt
,
err
:=
cur
.
GetLinkedNode
(
context
.
Background
(),
ds
,
e
)
nxt
,
err
:=
cur
.
GetLinkedNode
(
context
.
Background
(),
ds
,
e
)
...
...
mfs/mfs_test.go
浏览文件 @
743f3edc
...
@@ -8,12 +8,12 @@ import (
...
@@ -8,12 +8,12 @@ import (
"io/ioutil"
"io/ioutil"
"os"
"os"
"sort"
"sort"
"strings"
"testing"
"testing"
ds
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
ds
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
dssync
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
dssync
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/ipfs/go-ipfs/path"
bstore
"github.com/ipfs/go-ipfs/blocks/blockstore"
bstore
"github.com/ipfs/go-ipfs/blocks/blockstore"
key
"github.com/ipfs/go-ipfs/blocks/key"
key
"github.com/ipfs/go-ipfs/blocks/key"
...
@@ -43,8 +43,8 @@ func getRandFile(t *testing.T, ds dag.DAGService, size int64) *dag.Node {
...
@@ -43,8 +43,8 @@ func getRandFile(t *testing.T, ds dag.DAGService, size int64) *dag.Node {
return
nd
return
nd
}
}
func
mkdirP
(
t
*
testing
.
T
,
root
*
Directory
,
p
a
th
string
)
*
Directory
{
func
mkdirP
(
t
*
testing
.
T
,
root
*
Directory
,
pth
string
)
*
Directory
{
dirs
:=
strings
.
Split
(
path
,
"/"
)
dirs
:=
path
.
SplitList
(
pth
)
cur
:=
root
cur
:=
root
for
_
,
d
:=
range
dirs
{
for
_
,
d
:=
range
dirs
{
n
,
err
:=
cur
.
Mkdir
(
d
)
n
,
err
:=
cur
.
Mkdir
(
d
)
...
@@ -69,15 +69,15 @@ func mkdirP(t *testing.T, root *Directory, path string) *Directory {
...
@@ -69,15 +69,15 @@ func mkdirP(t *testing.T, root *Directory, path string) *Directory {
return
cur
return
cur
}
}
func
assertDirAtPath
(
root
*
Directory
,
p
a
th
string
,
children
[]
string
)
error
{
func
assertDirAtPath
(
root
*
Directory
,
pth
string
,
children
[]
string
)
error
{
fsn
,
err
:=
DirLookup
(
root
,
p
a
th
)
fsn
,
err
:=
DirLookup
(
root
,
pth
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
dir
,
ok
:=
fsn
.
(
*
Directory
)
dir
,
ok
:=
fsn
.
(
*
Directory
)
if
!
ok
{
if
!
ok
{
return
fmt
.
Errorf
(
"%s was not a directory"
,
p
a
th
)
return
fmt
.
Errorf
(
"%s was not a directory"
,
pth
)
}
}
listing
,
err
:=
dir
.
List
()
listing
,
err
:=
dir
.
List
()
...
@@ -113,13 +113,13 @@ func compStrArrs(a, b []string) bool {
...
@@ -113,13 +113,13 @@ func compStrArrs(a, b []string) bool {
return
true
return
true
}
}
func
assertFileAtPath
(
ds
dag
.
DAGService
,
root
*
Directory
,
exp
*
dag
.
Node
,
p
a
th
string
)
error
{
func
assertFileAtPath
(
ds
dag
.
DAGService
,
root
*
Directory
,
exp
*
dag
.
Node
,
pth
string
)
error
{
parts
:=
strings
.
Split
(
path
,
"/"
)
parts
:=
path
.
SplitList
(
pth
)
cur
:=
root
cur
:=
root
for
i
,
d
:=
range
parts
[
:
len
(
parts
)
-
1
]
{
for
i
,
d
:=
range
parts
[
:
len
(
parts
)
-
1
]
{
next
,
err
:=
cur
.
Child
(
d
)
next
,
err
:=
cur
.
Child
(
d
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"looking for %s failed: %s"
,
p
a
th
,
err
)
return
fmt
.
Errorf
(
"looking for %s failed: %s"
,
pth
,
err
)
}
}
nextDir
,
ok
:=
next
.
(
*
Directory
)
nextDir
,
ok
:=
next
.
(
*
Directory
)
...
@@ -138,7 +138,7 @@ func assertFileAtPath(ds dag.DAGService, root *Directory, exp *dag.Node, path st
...
@@ -138,7 +138,7 @@ func assertFileAtPath(ds dag.DAGService, root *Directory, exp *dag.Node, path st
file
,
ok
:=
finaln
.
(
*
File
)
file
,
ok
:=
finaln
.
(
*
File
)
if
!
ok
{
if
!
ok
{
return
fmt
.
Errorf
(
"%s was not a file!"
,
p
a
th
)
return
fmt
.
Errorf
(
"%s was not a file!"
,
pth
)
}
}
out
,
err
:=
ioutil
.
ReadAll
(
file
)
out
,
err
:=
ioutil
.
ReadAll
(
file
)
...
...
mfs/ops.go
浏览文件 @
743f3edc
...
@@ -101,7 +101,7 @@ func PutNode(r *Root, path string, nd *dag.Node) error {
...
@@ -101,7 +101,7 @@ func PutNode(r *Root, path string, nd *dag.Node) error {
// Mkdir creates a directory at 'path' under the directory 'd', creating
// Mkdir creates a directory at 'path' under the directory 'd', creating
// intermediary directories as needed if 'parents' is set to true
// intermediary directories as needed if 'parents' is set to true
func
Mkdir
(
r
*
Root
,
pth
string
,
parents
bool
)
error
{
func
Mkdir
(
r
*
Root
,
pth
string
,
parents
bool
)
error
{
parts
:=
strings
.
Split
(
pth
,
"/"
)
parts
:=
path
.
SplitList
(
pth
)
if
parts
[
0
]
==
""
{
if
parts
[
0
]
==
""
{
parts
=
parts
[
1
:
]
parts
=
parts
[
1
:
]
}
}
...
@@ -159,7 +159,7 @@ func Lookup(r *Root, path string) (FSNode, error) {
...
@@ -159,7 +159,7 @@ func Lookup(r *Root, path string) (FSNode, error) {
// under the directory 'd'
// under the directory 'd'
func
DirLookup
(
d
*
Directory
,
pth
string
)
(
FSNode
,
error
)
{
func
DirLookup
(
d
*
Directory
,
pth
string
)
(
FSNode
,
error
)
{
pth
=
strings
.
Trim
(
pth
,
"/"
)
pth
=
strings
.
Trim
(
pth
,
"/"
)
parts
:=
strings
.
Split
(
pth
,
"/"
)
parts
:=
path
.
SplitList
(
pth
)
if
len
(
parts
)
==
1
&&
parts
[
0
]
==
""
{
if
len
(
parts
)
==
1
&&
parts
[
0
]
==
""
{
return
d
,
nil
return
d
,
nil
}
}
...
...
path/path.go
浏览文件 @
743f3edc
...
@@ -106,3 +106,7 @@ func (p *Path) IsValid() error {
...
@@ -106,3 +106,7 @@ func (p *Path) IsValid() error {
func
Join
(
pths
[]
string
)
string
{
func
Join
(
pths
[]
string
)
string
{
return
strings
.
Join
(
pths
,
"/"
)
return
strings
.
Join
(
pths
,
"/"
)
}
}
func
SplitList
(
pth
string
)
[]
string
{
return
strings
.
Split
(
pth
,
"/"
)
}
routing/record/selection.go
浏览文件 @
743f3edc
...
@@ -2,9 +2,9 @@ package record
...
@@ -2,9 +2,9 @@ package record
import
(
import
(
"errors"
"errors"
"strings"
key
"github.com/ipfs/go-ipfs/blocks/key"
key
"github.com/ipfs/go-ipfs/blocks/key"
path
"github.com/ipfs/go-ipfs/path"
)
)
// A SelectorFunc selects the best value for the given key from
// A SelectorFunc selects the best value for the given key from
...
@@ -18,7 +18,7 @@ func (s Selector) BestRecord(k key.Key, recs [][]byte) (int, error) {
...
@@ -18,7 +18,7 @@ func (s Selector) BestRecord(k key.Key, recs [][]byte) (int, error) {
return
0
,
errors
.
New
(
"no records given!"
)
return
0
,
errors
.
New
(
"no records given!"
)
}
}
parts
:=
strings
.
Split
(
string
(
k
),
"/"
)
parts
:=
path
.
SplitList
(
string
(
k
)
)
if
len
(
parts
)
<
3
{
if
len
(
parts
)
<
3
{
log
.
Infof
(
"Record key does not have selectorfunc: %s"
,
k
)
log
.
Infof
(
"Record key does not have selectorfunc: %s"
,
k
)
return
0
,
errors
.
New
(
"record key does not have selectorfunc"
)
return
0
,
errors
.
New
(
"record key does not have selectorfunc"
)
...
...
routing/record/validation.go
浏览文件 @
743f3edc
...
@@ -3,10 +3,10 @@ package record
...
@@ -3,10 +3,10 @@ package record
import
(
import
(
"bytes"
"bytes"
"errors"
"errors"
"strings"
key
"github.com/ipfs/go-ipfs/blocks/key"
key
"github.com/ipfs/go-ipfs/blocks/key"
ci
"github.com/ipfs/go-ipfs/p2p/crypto"
ci
"github.com/ipfs/go-ipfs/p2p/crypto"
path
"github.com/ipfs/go-ipfs/path"
pb
"github.com/ipfs/go-ipfs/routing/dht/pb"
pb
"github.com/ipfs/go-ipfs/routing/dht/pb"
u
"github.com/ipfs/go-ipfs/util"
u
"github.com/ipfs/go-ipfs/util"
)
)
...
@@ -37,7 +37,7 @@ type ValidChecker struct {
...
@@ -37,7 +37,7 @@ type ValidChecker struct {
// It runs needed validators
// It runs needed validators
func
(
v
Validator
)
VerifyRecord
(
r
*
pb
.
Record
)
error
{
func
(
v
Validator
)
VerifyRecord
(
r
*
pb
.
Record
)
error
{
// Now, check validity func
// Now, check validity func
parts
:=
strings
.
Split
(
r
.
GetKey
(),
"/"
)
parts
:=
path
.
SplitList
(
r
.
GetKey
()
)
if
len
(
parts
)
<
3
{
if
len
(
parts
)
<
3
{
log
.
Infof
(
"Record key does not have validator: %s"
,
key
.
Key
(
r
.
GetKey
()))
log
.
Infof
(
"Record key does not have validator: %s"
,
key
.
Key
(
r
.
GetKey
()))
return
nil
return
nil
...
@@ -54,7 +54,7 @@ func (v Validator) VerifyRecord(r *pb.Record) error {
...
@@ -54,7 +54,7 @@ func (v Validator) VerifyRecord(r *pb.Record) error {
func
(
v
Validator
)
IsSigned
(
k
key
.
Key
)
(
bool
,
error
)
{
func
(
v
Validator
)
IsSigned
(
k
key
.
Key
)
(
bool
,
error
)
{
// Now, check validity func
// Now, check validity func
parts
:=
strings
.
Split
(
string
(
k
),
"/"
)
parts
:=
path
.
SplitList
(
string
(
k
)
)
if
len
(
parts
)
<
3
{
if
len
(
parts
)
<
3
{
log
.
Infof
(
"Record key does not have validator: %s"
,
k
)
log
.
Infof
(
"Record key does not have validator: %s"
,
k
)
return
false
,
nil
return
false
,
nil
...
...
tar/format.go
浏览文件 @
743f3edc
...
@@ -98,7 +98,7 @@ func ImportTar(r io.Reader, ds dag.DAGService) (*dag.Node, error) {
...
@@ -98,7 +98,7 @@ func ImportTar(r io.Reader, ds dag.DAGService) (*dag.Node, error) {
// adds a '-' to the beginning of each path element so we can use 'data' as a
// adds a '-' to the beginning of each path element so we can use 'data' as a
// special link in the structure without having to worry about
// special link in the structure without having to worry about
func
escapePath
(
pth
string
)
string
{
func
escapePath
(
pth
string
)
string
{
elems
:=
strings
.
Split
(
strings
.
Trim
(
pth
,
"/"
),
"/"
)
elems
:=
path
.
SplitList
(
strings
.
Trim
(
pth
,
"/"
)
)
for
i
,
e
:=
range
elems
{
for
i
,
e
:=
range
elems
{
elems
[
i
]
=
"-"
+
e
elems
[
i
]
=
"-"
+
e
}
}
...
...
util/ipfsaddr/ipfsaddr.go
浏览文件 @
743f3edc
...
@@ -2,11 +2,11 @@ package ipfsaddr
...
@@ -2,11 +2,11 @@ package ipfsaddr
import
(
import
(
"errors"
"errors"
"strings"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
path
"github.com/ipfs/go-ipfs/path"
logging
"github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
logging
"github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
)
)
...
@@ -94,7 +94,7 @@ func ParseMultiaddr(m ma.Multiaddr) (a IPFSAddr, err error) {
...
@@ -94,7 +94,7 @@ func ParseMultiaddr(m ma.Multiaddr) (a IPFSAddr, err error) {
}
}
// make sure ipfs id parses as a peer.ID
// make sure ipfs id parses as a peer.ID
peerIdParts
:=
strings
.
Split
(
ipfspart
.
String
(),
"/"
)
peerIdParts
:=
path
.
SplitList
(
ipfspart
.
String
()
)
peerIdStr
:=
peerIdParts
[
len
(
peerIdParts
)
-
1
]
peerIdStr
:=
peerIdParts
[
len
(
peerIdParts
)
-
1
]
id
,
err
:=
peer
.
IDB58Decode
(
peerIdStr
)
id
,
err
:=
peer
.
IDB58Decode
(
peerIdStr
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
util/ipfsaddr/ipfsaddr_test.go
浏览文件 @
743f3edc
package
ipfsaddr
package
ipfsaddr
import
(
import
(
"strings"
"testing"
"testing"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
path
"github.com/ipfs/go-ipfs/path"
)
)
var
good
=
[]
string
{
var
good
=
[]
string
{
...
@@ -87,7 +87,7 @@ func TestIDMatches(t *testing.T) {
...
@@ -87,7 +87,7 @@ func TestIDMatches(t *testing.T) {
continue
continue
}
}
sp
:=
strings
.
Split
(
g
,
"/"
)
sp
:=
path
.
SplitList
(
g
)
sid
:=
sp
[
len
(
sp
)
-
1
]
sid
:=
sp
[
len
(
sp
)
-
1
]
id
,
err
:=
peer
.
IDB58Decode
(
sid
)
id
,
err
:=
peer
.
IDB58Decode
(
sid
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论