Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
interface-go-dms3-core
Commits
21a72398
Commit
21a72398
authored
Mar 26, 2019
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path: rename ParsePath and ResolvedPath
parent
5a836515
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
33 additions
and
37 deletions
+33
-37
block.go
block.go
+1
-1
coreapi.go
coreapi.go
+1
-1
object.go
object.go
+7
-7
path.go
path.go
+0
-4
path/path.go
path/path.go
+8
-8
pin.go
pin.go
+2
-2
tests/block.go
tests/block.go
+1
-1
tests/dag.go
tests/dag.go
+1
-1
tests/name.go
tests/name.go
+1
-1
tests/path.go
tests/path.go
+5
-5
tests/unixfs.go
tests/unixfs.go
+2
-2
unixfs.go
unixfs.go
+4
-4
No files found.
block.go
View file @
21a72398
...
@@ -14,7 +14,7 @@ type BlockStat interface {
...
@@ -14,7 +14,7 @@ type BlockStat interface {
Size
()
int
Size
()
int
// Path returns path to the block
// Path returns path to the block
Path
()
path
.
Resolved
Path
Path
()
path
.
Resolved
}
}
// BlockAPI specifies the interface to the block layer
// BlockAPI specifies the interface to the block layer
...
...
coreapi.go
View file @
21a72398
...
@@ -44,7 +44,7 @@ type CoreAPI interface {
...
@@ -44,7 +44,7 @@ type CoreAPI interface {
PubSub
()
PubSubAPI
PubSub
()
PubSubAPI
// ResolvePath resolves the path using Unixfs resolver
// ResolvePath resolves the path using Unixfs resolver
ResolvePath
(
context
.
Context
,
path
.
Path
)
(
path
.
Resolved
Path
,
error
)
ResolvePath
(
context
.
Context
,
path
.
Path
)
(
path
.
Resolved
,
error
)
// ResolveNode resolves the path (if not resolved already) using Unixfs
// ResolveNode resolves the path (if not resolved already) using Unixfs
// resolver, gets and returns the resolved Node
// resolver, gets and returns the resolved Node
...
...
object.go
View file @
21a72398
...
@@ -59,11 +59,11 @@ type ObjectChange struct {
...
@@ -59,11 +59,11 @@ type ObjectChange struct {
// Before holds the link path before the change. Note that when a link is
// Before holds the link path before the change. Note that when a link is
// added, this will be nil.
// added, this will be nil.
Before
path
.
Resolved
Path
Before
path
.
Resolved
// After holds the link path after the change. Note that when a link is
// After holds the link path after the change. Note that when a link is
// removed, this will be nil.
// removed, this will be nil.
After
path
.
Resolved
Path
After
path
.
Resolved
}
}
// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
...
@@ -73,7 +73,7 @@ type ObjectAPI interface {
...
@@ -73,7 +73,7 @@ type ObjectAPI interface {
New
(
context
.
Context
,
...
options
.
ObjectNewOption
)
(
ipld
.
Node
,
error
)
New
(
context
.
Context
,
...
options
.
ObjectNewOption
)
(
ipld
.
Node
,
error
)
// Put imports the data into merkledag
// Put imports the data into merkledag
Put
(
context
.
Context
,
io
.
Reader
,
...
options
.
ObjectPutOption
)
(
path
.
Resolved
Path
,
error
)
Put
(
context
.
Context
,
io
.
Reader
,
...
options
.
ObjectPutOption
)
(
path
.
Resolved
,
error
)
// Get returns the node for the path
// Get returns the node for the path
Get
(
context
.
Context
,
path
.
Path
)
(
ipld
.
Node
,
error
)
Get
(
context
.
Context
,
path
.
Path
)
(
ipld
.
Node
,
error
)
...
@@ -90,16 +90,16 @@ type ObjectAPI interface {
...
@@ -90,16 +90,16 @@ type ObjectAPI interface {
// AddLink adds a link under the specified path. child path can point to a
// AddLink adds a link under the specified path. child path can point to a
// subdirectory within the patent which must be present (can be overridden
// subdirectory within the patent which must be present (can be overridden
// with WithCreate option).
// with WithCreate option).
AddLink
(
ctx
context
.
Context
,
base
path
.
Path
,
name
string
,
child
path
.
Path
,
opts
...
options
.
ObjectAddLinkOption
)
(
path
.
Resolved
Path
,
error
)
AddLink
(
ctx
context
.
Context
,
base
path
.
Path
,
name
string
,
child
path
.
Path
,
opts
...
options
.
ObjectAddLinkOption
)
(
path
.
Resolved
,
error
)
// RmLink removes a link from the node
// RmLink removes a link from the node
RmLink
(
ctx
context
.
Context
,
base
path
.
Path
,
link
string
)
(
path
.
Resolved
Path
,
error
)
RmLink
(
ctx
context
.
Context
,
base
path
.
Path
,
link
string
)
(
path
.
Resolved
,
error
)
// AppendData appends data to the node
// AppendData appends data to the node
AppendData
(
context
.
Context
,
path
.
Path
,
io
.
Reader
)
(
path
.
Resolved
Path
,
error
)
AppendData
(
context
.
Context
,
path
.
Path
,
io
.
Reader
)
(
path
.
Resolved
,
error
)
// SetData sets the data contained in the node
// SetData sets the data contained in the node
SetData
(
context
.
Context
,
path
.
Path
,
io
.
Reader
)
(
path
.
Resolved
Path
,
error
)
SetData
(
context
.
Context
,
path
.
Path
,
io
.
Reader
)
(
path
.
Resolved
,
error
)
// Diff returns a set of changes needed to transform the first object into the
// Diff returns a set of changes needed to transform the first object into the
// second.
// second.
...
...
path.go
deleted
100644 → 0
View file @
5a836515
package
iface
//TODO: merge with ipfspath so we don't depend on it
path/path.go
View file @
21a72398
...
@@ -39,9 +39,9 @@ type Path interface {
...
@@ -39,9 +39,9 @@ type Path interface {
IsValid
()
error
IsValid
()
error
}
}
// Resolved
Path
is a path which was resolved to the last resolvable node.
// Resolved is a path which was resolved to the last resolvable node.
// ResolvedPaths are guaranteed to return nil from `IsValid`
// ResolvedPaths are guaranteed to return nil from `IsValid`
type
Resolved
Path
interface
{
type
Resolved
interface
{
// Cid returns the CID of the node referenced by the path. Remainder of the
// Cid returns the CID of the node referenced by the path. Remainder of the
// path is guaranteed to be within the node.
// path is guaranteed to be within the node.
//
//
...
@@ -120,7 +120,7 @@ func Join(base Path, a ...string) Path {
...
@@ -120,7 +120,7 @@ func Join(base Path, a ...string) Path {
}
}
// IpfsPath creates new /ipfs path from the provided CID
// IpfsPath creates new /ipfs path from the provided CID
func
IpfsPath
(
c
cid
.
Cid
)
Resolved
Path
{
func
IpfsPath
(
c
cid
.
Cid
)
Resolved
{
return
&
resolvedPath
{
return
&
resolvedPath
{
path
:
path
{
"/ipfs/"
+
c
.
String
()},
path
:
path
{
"/ipfs/"
+
c
.
String
()},
cid
:
c
,
cid
:
c
,
...
@@ -130,7 +130,7 @@ func IpfsPath(c cid.Cid) ResolvedPath {
...
@@ -130,7 +130,7 @@ func IpfsPath(c cid.Cid) ResolvedPath {
}
}
// IpldPath creates new /ipld path from the provided CID
// IpldPath creates new /ipld path from the provided CID
func
IpldPath
(
c
cid
.
Cid
)
Resolved
Path
{
func
IpldPath
(
c
cid
.
Cid
)
Resolved
{
return
&
resolvedPath
{
return
&
resolvedPath
{
path
:
path
{
"/ipld/"
+
c
.
String
()},
path
:
path
{
"/ipld/"
+
c
.
String
()},
cid
:
c
,
cid
:
c
,
...
@@ -139,8 +139,8 @@ func IpldPath(c cid.Cid) ResolvedPath {
...
@@ -139,8 +139,8 @@ func IpldPath(c cid.Cid) ResolvedPath {
}
}
}
}
//
ParsePath
parses string path to a Path
//
New
parses string path to a Path
func
ParsePath
(
p
string
)
Path
{
func
New
(
p
string
)
Path
{
if
pp
,
err
:=
ipfspath
.
ParsePath
(
p
);
err
==
nil
{
if
pp
,
err
:=
ipfspath
.
ParsePath
(
p
);
err
==
nil
{
p
=
pp
.
String
()
p
=
pp
.
String
()
}
}
...
@@ -148,10 +148,10 @@ func ParsePath(p string) Path {
...
@@ -148,10 +148,10 @@ func ParsePath(p string) Path {
return
&
path
{
path
:
p
}
return
&
path
{
path
:
p
}
}
}
// NewResolvedPath creates new Resolved
P
ath. This function performs no checks
// NewResolvedPath creates new Resolved
p
ath. This function performs no checks
// and is intended to be used by resolver implementations. Incorrect inputs may
// and is intended to be used by resolver implementations. Incorrect inputs may
// cause panics. Handle with care.
// cause panics. Handle with care.
func
NewResolvedPath
(
ipath
ipfspath
.
Path
,
c
cid
.
Cid
,
root
cid
.
Cid
,
remainder
string
)
Resolved
Path
{
func
NewResolvedPath
(
ipath
ipfspath
.
Path
,
c
cid
.
Cid
,
root
cid
.
Cid
,
remainder
string
)
Resolved
{
return
&
resolvedPath
{
return
&
resolvedPath
{
path
:
path
{
ipath
.
String
()},
path
:
path
{
ipath
.
String
()},
cid
:
c
,
cid
:
c
,
...
...
pin.go
View file @
21a72398
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
// Pin holds information about pinned resource
// Pin holds information about pinned resource
type
Pin
interface
{
type
Pin
interface
{
// Path to the pinned object
// Path to the pinned object
Path
()
path
.
Resolved
Path
Path
()
path
.
Resolved
// Type of the pin
// Type of the pin
Type
()
string
Type
()
string
...
@@ -28,7 +28,7 @@ type PinStatus interface {
...
@@ -28,7 +28,7 @@ type PinStatus interface {
// BadPinNode is a node that has been marked as bad by Pin.Verify
// BadPinNode is a node that has been marked as bad by Pin.Verify
type
BadPinNode
interface
{
type
BadPinNode
interface
{
// Path is the path of the node
// Path is the path of the node
Path
()
path
.
Resolved
Path
Path
()
path
.
Resolved
// Err is the reason why the node has been marked as bad
// Err is the reason why the node has been marked as bad
Err
()
error
Err
()
error
...
...
tests/block.go
View file @
21a72398
...
@@ -111,7 +111,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
...
@@ -111,7 +111,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
t
.
Error
(
"didn't get correct data back"
)
t
.
Error
(
"didn't get correct data back"
)
}
}
p
:=
path
.
ParsePath
(
"/ipfs/"
+
res
.
Path
()
.
Cid
()
.
String
())
p
:=
path
.
New
(
"/ipfs/"
+
res
.
Path
()
.
Cid
()
.
String
())
rp
,
err
:=
api
.
ResolvePath
(
ctx
,
p
)
rp
,
err
:=
api
.
ResolvePath
(
ctx
,
p
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
tests/dag.go
View file @
21a72398
...
@@ -114,7 +114,7 @@ func (tp *provider) TestDagPath(t *testing.T) {
...
@@ -114,7 +114,7 @@ func (tp *provider) TestDagPath(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
p
:=
path
.
ParsePath
(
gopath
.
Join
(
nd
.
Cid
()
.
String
(),
"lnk"
))
p
:=
path
.
New
(
gopath
.
Join
(
nd
.
Cid
()
.
String
(),
"lnk"
))
rp
,
err
:=
api
.
ResolvePath
(
ctx
,
p
)
rp
,
err
:=
api
.
ResolvePath
(
ctx
,
p
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
tests/name.go
View file @
21a72398
...
@@ -36,7 +36,7 @@ func addTestObject(ctx context.Context, api coreiface.CoreAPI) (path.Path, error
...
@@ -36,7 +36,7 @@ func addTestObject(ctx context.Context, api coreiface.CoreAPI) (path.Path, error
}
}
func
appendPath
(
p
path
.
Path
,
sub
string
)
path
.
Path
{
func
appendPath
(
p
path
.
Path
,
sub
string
)
path
.
Path
{
return
path
.
ParsePath
(
gopath
.
Join
(
p
.
String
(),
sub
))
return
path
.
New
(
gopath
.
Join
(
p
.
String
(),
sub
))
}
}
func
(
tp
*
provider
)
TestPublishResolve
(
t
*
testing
.
T
)
{
func
(
tp
*
provider
)
TestPublishResolve
(
t
*
testing
.
T
)
{
...
...
tests/path.go
View file @
21a72398
...
@@ -75,7 +75,7 @@ func (tp *provider) TestPathRemainder(t *testing.T) {
...
@@ -75,7 +75,7 @@ func (tp *provider) TestPathRemainder(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
rp1
,
err
:=
api
.
ResolvePath
(
ctx
,
path
.
ParsePath
(
nd
.
String
()
+
"/foo/bar"
))
rp1
,
err
:=
api
.
ResolvePath
(
ctx
,
path
.
New
(
nd
.
String
()
+
"/foo/bar"
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -106,7 +106,7 @@ func (tp *provider) TestEmptyPathRemainder(t *testing.T) {
...
@@ -106,7 +106,7 @@ func (tp *provider) TestEmptyPathRemainder(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
rp1
,
err
:=
api
.
ResolvePath
(
ctx
,
path
.
ParsePath
(
nd
.
Cid
()
.
String
()))
rp1
,
err
:=
api
.
ResolvePath
(
ctx
,
path
.
New
(
nd
.
Cid
()
.
String
()))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -137,7 +137,7 @@ func (tp *provider) TestInvalidPathRemainder(t *testing.T) {
...
@@ -137,7 +137,7 @@ func (tp *provider) TestInvalidPathRemainder(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
_
,
err
=
api
.
ResolvePath
(
ctx
,
path
.
ParsePath
(
"/ipld/"
+
nd
.
Cid
()
.
String
()
+
"/bar/baz"
))
_
,
err
=
api
.
ResolvePath
(
ctx
,
path
.
New
(
"/ipld/"
+
nd
.
Cid
()
.
String
()
+
"/bar/baz"
))
if
err
==
nil
||
!
strings
.
Contains
(
err
.
Error
(),
"no such link found"
)
{
if
err
==
nil
||
!
strings
.
Contains
(
err
.
Error
(),
"no such link found"
)
{
t
.
Fatalf
(
"unexpected error: %s"
,
err
)
t
.
Fatalf
(
"unexpected error: %s"
,
err
)
}
}
...
@@ -173,7 +173,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
...
@@ -173,7 +173,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
rp
,
err
:=
api
.
ResolvePath
(
ctx
,
path
.
ParsePath
(
"/ipld/"
+
nd
.
Cid
()
.
String
()
+
"/foo"
))
rp
,
err
:=
api
.
ResolvePath
(
ctx
,
path
.
New
(
"/ipld/"
+
nd
.
Cid
()
.
String
()
+
"/foo"
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -188,7 +188,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
...
@@ -188,7 +188,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
}
}
func
(
tp
*
provider
)
TestPathJoin
(
t
*
testing
.
T
)
{
func
(
tp
*
provider
)
TestPathJoin
(
t
*
testing
.
T
)
{
p1
:=
path
.
ParsePath
(
"/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz"
)
p1
:=
path
.
New
(
"/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz"
)
if
path
.
Join
(
p1
,
"foo"
)
.
String
()
!=
"/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz/foo"
{
if
path
.
Join
(
p1
,
"foo"
)
.
String
()
!=
"/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz/foo"
{
t
.
Error
(
"unexpected path"
)
t
.
Error
(
"unexpected path"
)
...
...
tests/unixfs.go
View file @
21a72398
...
@@ -102,7 +102,7 @@ func (tp *provider) TestAdd(t *testing.T) {
...
@@ -102,7 +102,7 @@ func (tp *provider) TestAdd(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
p
:=
func
(
h
string
)
path
.
Resolved
Path
{
p
:=
func
(
h
string
)
path
.
Resolved
{
c
,
err
:=
cid
.
Parse
(
h
)
c
,
err
:=
cid
.
Parse
(
h
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -593,7 +593,7 @@ func (tp *provider) TestGetEmptyFile(t *testing.T) {
...
@@ -593,7 +593,7 @@ func (tp *provider) TestGetEmptyFile(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
emptyFilePath
:=
path
.
ParsePath
(
emptyFile
)
emptyFilePath
:=
path
.
New
(
emptyFile
)
r
,
err
:=
api
.
Unixfs
()
.
Get
(
ctx
,
emptyFilePath
)
r
,
err
:=
api
.
Unixfs
()
.
Get
(
ctx
,
emptyFilePath
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
unixfs.go
View file @
21a72398
...
@@ -11,9 +11,9 @@ import (
...
@@ -11,9 +11,9 @@ import (
type
AddEvent
struct
{
type
AddEvent
struct
{
Name
string
Name
string
Path
path
.
Resolved
Path
`json:",omitempty"`
Path
path
.
Resolved
`json:",omitempty"`
Bytes
int64
`json:",omitempty"`
Bytes
int64
`json:",omitempty"`
Size
string
`json:",omitempty"`
Size
string
`json:",omitempty"`
}
}
// FileType is an enum of possible UnixFS file types.
// FileType is an enum of possible UnixFS file types.
...
@@ -65,7 +65,7 @@ type UnixfsAPI interface {
...
@@ -65,7 +65,7 @@ type UnixfsAPI interface {
// Add imports the data from the reader into merkledag file
// Add imports the data from the reader into merkledag file
//
//
// TODO: a long useful comment on how to use this for many different scenarios
// TODO: a long useful comment on how to use this for many different scenarios
Add
(
context
.
Context
,
files
.
Node
,
...
options
.
UnixfsAddOption
)
(
path
.
Resolved
Path
,
error
)
Add
(
context
.
Context
,
files
.
Node
,
...
options
.
UnixfsAddOption
)
(
path
.
Resolved
,
error
)
// Get returns a read-only handle to a file tree referenced by a path
// Get returns a read-only handle to a file tree referenced by a path
//
//
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment