Commit d23ae11e authored by tavit ohanian's avatar tavit ohanian

more fixes

parent bbea2985
...@@ -17,8 +17,8 @@ type CoreAPI interface { ...@@ -17,8 +17,8 @@ type CoreAPI interface {
// Unixfs returns an implementation of Unixfs API // Unixfs returns an implementation of Unixfs API
Unixfs() UnixfsAPI Unixfs() UnixfsAPI
// Index returns the IndexAPI interface implementation backed by the go-dms3fs node // Index returns the IndexAPI interface implementation backed by the go-dms3 node
// Index() IndexAPI Index() IndexAPI
// Block returns an implementation of Block API // Block returns an implementation of Block API
Block() BlockAPI Block() BlockAPI
......
This diff is collapsed.
package iface
import (
"context"
// "io"
options "gitlab.dms3.io/dms3/interface-go-dms3-core/options"
corepath "gitlab.dms3.io/dms3/interface-go-dms3-core/path"
path "gitlab.dms3.io/dms3/interface-go-dms3-core/path"
// dms3ld "gitlab.dms3.io/dms3/go-ld-format"
)
// IndexMakeEvent modeled after Unixfs AddEvent
type IndexMakeEvent struct {
Name string
Path path.Resolved `json:",omitempty"`
Bytes int64 `json:",omitempty"`
Size string `json:",omitempty"`
}
// RepoList interface {
type RepoList interface {
// Name returns repository name
Name() string
// Id returns repository path
Id() string
}
//type RepoList []RepoEntry
// IndexAPI is the basic interface to immutable files in DMS3
type IndexAPI interface {
// Add imports the data from the reader into merkledag file
//Add(context.Context, io.Reader) (ResolvedPath, error)
// Cat returns a reader for the file
//Cat(context.Context, Path) (Reader, error)
Index(ctx context.Context, path corepath.Path, opts ...options.IndexListOption) (RepoList, error)
// Ls returns the list of links in a directory
//Ls(context.Context, Path) ([]*dms3ld.Link, error)
}
package options
// Index option constants
const (
RepoWindowStart = iota
)
// IndexMakeSettings mkidx option settings
type IndexMakeSettings struct {
Events chan<- interface{}
Quiet bool
Progress bool
}
// IndexListSettings ls option settings
type IndexListSettings struct {
Meta string
}
// IndexMakeOption make options type
type IndexMakeOption func(*IndexMakeSettings) error
// IndexListOption ls options type
type IndexListOption func(*IndexListSettings) error
// IndexMakeOptions make options function
func IndexMakeOptions(opts ...IndexMakeOption) (*IndexMakeSettings, error) {
options := &IndexMakeSettings{
Events: nil,
Quiet: false,
Progress: false,
}
for _, opt := range opts {
err := opt(options)
if err != nil {
return nil, err
}
}
return options, nil
}
type indexMakeOpts struct{}
// IndexMake options
var IndexMake indexMakeOpts
// Events specifies channel which will be used to report events about ongoing
// Make operation.
//
// Note that if this channel blocks it may slowdown the make
func (indexMakeOpts) Events(sink chan<- interface{}) IndexMakeOption {
return func(settings *IndexMakeSettings) error {
settings.Events = sink
return nil
}
}
// Quiet reduces event output
func (indexMakeOpts) Quiet(quiet bool) IndexMakeOption {
return func(settings *IndexMakeSettings) error {
settings.Quiet = quiet
return nil
}
}
// Progress tells make whether to enable progress events
func (indexMakeOpts) Progress(enable bool) IndexMakeOption {
return func(settings *IndexMakeSettings) error {
settings.Progress = enable
return nil
}
}
// IndexListOptions ls options function
func IndexListOptions(opts ...IndexListOption) (*IndexListSettings, error) {
options := &IndexListSettings{
Meta: "",
}
for _, opt := range opts {
err := opt(options)
if err != nil {
return nil, err
}
}
return options, nil
}
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
// Paths must be prefixed with a valid prefix: // Paths must be prefixed with a valid prefix:
// //
// * /dms3 - Immutable unixfs path (files) // * /dms3 - Immutable unixfs path (files)
// * /dms3ld - Immutable dms3ld path (data) // * /ld - Immutable ld path (data)
// * /dms3ns - Mutable names. Usually resolves to one of the immutable paths // * /dms3ns - Mutable names. Usually resolves to one of the immutable paths
//TODO: /local (MFS) //TODO: /local (MFS)
type Path interface { type Path interface {
...@@ -92,7 +92,7 @@ type Resolved interface { ...@@ -92,7 +92,7 @@ type Resolved interface {
// //
// {"foo": {"bar": 42 }} // {"foo": {"bar": 42 }}
// //
// When resolving "/dms3ld/QmRoot/A/foo/bar", Remainder will return "foo/bar" // When resolving "/ld/QmRoot/A/foo/bar", Remainder will return "foo/bar"
// //
// For more examples see the documentation of Cid() method // For more examples see the documentation of Cid() method
Remainder() string Remainder() string
...@@ -129,10 +129,10 @@ func Dms3Path(c cid.Cid) Resolved { ...@@ -129,10 +129,10 @@ func Dms3Path(c cid.Cid) Resolved {
} }
} }
// Dms3LdPath creates new /dms3ld path from the provided CID // LdPath creates new /ld path from the provided CID
func Dms3LdPath(c cid.Cid) Resolved { func LdPath(c cid.Cid) Resolved {
return &resolvedPath{ return &resolvedPath{
path: path{"/dms3ld/" + c.String()}, path: path{"/ld/" + c.String()},
cid: c, cid: c,
root: c, root: c,
remainder: "", remainder: "",
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"gitlab.dms3.io/p2p/go-p2p-core/peer" "gitlab.dms3.io/p2p/go-p2p-core/peer"
"gitlab.dms3.io/p2p/go-p2p-core/protocol" "gitlab.dms3.io/p2p/go-p2p-core/protocol"
ma "github.com/multiformats/go-multiaddr" ma "gitlab.dms3.io/mf/go-multiaddr"
) )
var ( var (
......
...@@ -134,12 +134,12 @@ func (tp *TestSuite) TestPinRecursive(t *testing.T) { ...@@ -134,12 +134,12 @@ func (tp *TestSuite) TestPinRecursive(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
err = api.Pin().Add(ctx, path.Dms3LdPath(nd2.Cid())) err = api.Pin().Add(ctx, path.LdPath(nd2.Cid()))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = api.Pin().Add(ctx, path.Dms3LdPath(nd3.Cid()), opt.Pin.Recursive(false)) err = api.Pin().Add(ctx, path.LdPath(nd3.Cid()), opt.Pin.Recursive(false))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -162,7 +162,7 @@ func (tp *TestSuite) TestPinRecursive(t *testing.T) { ...@@ -162,7 +162,7 @@ func (tp *TestSuite) TestPinRecursive(t *testing.T) {
t.Errorf("unexpected pin list len: %d", len(list)) t.Errorf("unexpected pin list len: %d", len(list))
} }
if list[0].Path().String() != path.Dms3LdPath(nd3.Cid()).String() { if list[0].Path().String() != path.LdPath(nd3.Cid()).String() {
t.Errorf("unexpected path, %s != %s", list[0].Path().String(), path.Dms3Path(nd3.Cid()).String()) t.Errorf("unexpected path, %s != %s", list[0].Path().String(), path.Dms3Path(nd3.Cid()).String())
} }
...@@ -175,8 +175,8 @@ func (tp *TestSuite) TestPinRecursive(t *testing.T) { ...@@ -175,8 +175,8 @@ func (tp *TestSuite) TestPinRecursive(t *testing.T) {
t.Errorf("unexpected pin list len: %d", len(list)) t.Errorf("unexpected pin list len: %d", len(list))
} }
if list[0].Path().String() != path.Dms3LdPath(nd2.Cid()).String() { if list[0].Path().String() != path.LdPath(nd2.Cid()).String() {
t.Errorf("unexpected path, %s != %s", list[0].Path().String(), path.Dms3LdPath(nd2.Cid()).String()) t.Errorf("unexpected path, %s != %s", list[0].Path().String(), path.LdPath(nd2.Cid()).String())
} }
list, err = accPins(api.Pin().Ls(ctx, opt.Pin.Ls.Indirect())) list, err = accPins(api.Pin().Ls(ctx, opt.Pin.Ls.Indirect()))
...@@ -256,12 +256,12 @@ func (tp *TestSuite) TestPinLsIndirect(t *testing.T) { ...@@ -256,12 +256,12 @@ func (tp *TestSuite) TestPinLsIndirect(t *testing.T) {
leaf, parent, grandparent := getThreeChainedNodes(t, ctx, api, "foo") leaf, parent, grandparent := getThreeChainedNodes(t, ctx, api, "foo")
err = api.Pin().Add(ctx, path.Dms3LdPath(grandparent.Cid())) err = api.Pin().Add(ctx, path.LdPath(grandparent.Cid()))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = api.Pin().Add(ctx, path.Dms3LdPath(parent.Cid()), opt.Pin.Recursive(false)) err = api.Pin().Add(ctx, path.LdPath(parent.Cid()), opt.Pin.Recursive(false))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -290,12 +290,12 @@ func (tp *TestSuite) TestPinLsPredenceRecursiveIndirect(t *testing.T) { ...@@ -290,12 +290,12 @@ func (tp *TestSuite) TestPinLsPredenceRecursiveIndirect(t *testing.T) {
// Test recursive > indirect // Test recursive > indirect
leaf, parent, grandparent := getThreeChainedNodes(t, ctx, api, "recursive > indirect") leaf, parent, grandparent := getThreeChainedNodes(t, ctx, api, "recursive > indirect")
err = api.Pin().Add(ctx, path.Dms3LdPath(grandparent.Cid())) err = api.Pin().Add(ctx, path.LdPath(grandparent.Cid()))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = api.Pin().Add(ctx, path.Dms3LdPath(parent.Cid())) err = api.Pin().Add(ctx, path.LdPath(parent.Cid()))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -314,12 +314,12 @@ func (tp *TestSuite) TestPinLsPrecedenceDirectIndirect(t *testing.T) { ...@@ -314,12 +314,12 @@ func (tp *TestSuite) TestPinLsPrecedenceDirectIndirect(t *testing.T) {
// Test direct > indirect // Test direct > indirect
leaf, parent, grandparent := getThreeChainedNodes(t, ctx, api, "direct > indirect") leaf, parent, grandparent := getThreeChainedNodes(t, ctx, api, "direct > indirect")
err = api.Pin().Add(ctx, path.Dms3LdPath(grandparent.Cid())) err = api.Pin().Add(ctx, path.LdPath(grandparent.Cid()))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = api.Pin().Add(ctx, path.Dms3LdPath(parent.Cid()), opt.Pin.Recursive(false)) err = api.Pin().Add(ctx, path.LdPath(parent.Cid()), opt.Pin.Recursive(false))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -338,24 +338,24 @@ func (tp *TestSuite) TestPinLsPrecedenceRecursiveDirect(t *testing.T) { ...@@ -338,24 +338,24 @@ func (tp *TestSuite) TestPinLsPrecedenceRecursiveDirect(t *testing.T) {
// Test recursive > direct // Test recursive > direct
leaf, parent, grandparent := getThreeChainedNodes(t, ctx, api, "recursive + direct = error") leaf, parent, grandparent := getThreeChainedNodes(t, ctx, api, "recursive + direct = error")
err = api.Pin().Add(ctx, path.Dms3LdPath(parent.Cid())) err = api.Pin().Add(ctx, path.LdPath(parent.Cid()))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = api.Pin().Add(ctx, path.Dms3LdPath(parent.Cid()), opt.Pin.Recursive(false)) err = api.Pin().Add(ctx, path.LdPath(parent.Cid()), opt.Pin.Recursive(false))
if err == nil { if err == nil {
t.Fatal("expected error directly pinning a recursively pinned node") t.Fatal("expected error directly pinning a recursively pinned node")
} }
assertPinTypes(t, ctx, api, []cidContainer{parent}, []cidContainer{}, []cidContainer{leaf}) assertPinTypes(t, ctx, api, []cidContainer{parent}, []cidContainer{}, []cidContainer{leaf})
err = api.Pin().Add(ctx, path.Dms3LdPath(grandparent.Cid()), opt.Pin.Recursive(false)) err = api.Pin().Add(ctx, path.LdPath(grandparent.Cid()), opt.Pin.Recursive(false))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = api.Pin().Add(ctx, path.Dms3LdPath(grandparent.Cid())) err = api.Pin().Add(ctx, path.LdPath(grandparent.Cid()))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -373,27 +373,27 @@ func (tp *TestSuite) TestPinIsPinned(t *testing.T) { ...@@ -373,27 +373,27 @@ func (tp *TestSuite) TestPinIsPinned(t *testing.T) {
leaf, parent, grandparent := getThreeChainedNodes(t, ctx, api, "foofoo") leaf, parent, grandparent := getThreeChainedNodes(t, ctx, api, "foofoo")
assertNotPinned(t, ctx, api, path.Dms3LdPath(grandparent.Cid())) assertNotPinned(t, ctx, api, path.LdPath(grandparent.Cid()))
assertNotPinned(t, ctx, api, path.Dms3LdPath(parent.Cid())) assertNotPinned(t, ctx, api, path.LdPath(parent.Cid()))
assertNotPinned(t, ctx, api, path.Dms3LdPath(leaf.Cid())) assertNotPinned(t, ctx, api, path.LdPath(leaf.Cid()))
err = api.Pin().Add(ctx, path.Dms3LdPath(parent.Cid()), opt.Pin.Recursive(true)) err = api.Pin().Add(ctx, path.LdPath(parent.Cid()), opt.Pin.Recursive(true))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
assertNotPinned(t, ctx, api, path.Dms3LdPath(grandparent.Cid())) assertNotPinned(t, ctx, api, path.LdPath(grandparent.Cid()))
assertIsPinned(t, ctx, api, path.Dms3LdPath(parent.Cid()), "recursive") assertIsPinned(t, ctx, api, path.LdPath(parent.Cid()), "recursive")
assertIsPinned(t, ctx, api, path.Dms3LdPath(leaf.Cid()), "indirect") assertIsPinned(t, ctx, api, path.LdPath(leaf.Cid()), "indirect")
err = api.Pin().Add(ctx, path.Dms3LdPath(grandparent.Cid()), opt.Pin.Recursive(false)) err = api.Pin().Add(ctx, path.LdPath(grandparent.Cid()), opt.Pin.Recursive(false))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
assertIsPinned(t, ctx, api, path.Dms3LdPath(grandparent.Cid()), "direct") assertIsPinned(t, ctx, api, path.LdPath(grandparent.Cid()), "direct")
assertIsPinned(t, ctx, api, path.Dms3LdPath(parent.Cid()), "recursive") assertIsPinned(t, ctx, api, path.LdPath(parent.Cid()), "recursive")
assertIsPinned(t, ctx, api, path.Dms3LdPath(leaf.Cid()), "indirect") assertIsPinned(t, ctx, api, path.LdPath(leaf.Cid()), "indirect")
} }
type cidContainer interface { type cidContainer interface {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment