Commit 5fa31f8e authored by Brian Tiger Chow's avatar Brian Tiger Chow

deps(go-datastore) update

This commit updates go-datastore in order to access new LevelDb Close()
method

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 4af3e0ff
......@@ -99,7 +99,7 @@
},
{
"ImportPath": "github.com/jbenet/go-datastore",
"Rev": "da593f5071b3ce60bf45b548193863bc3c885c3c"
"Rev": "b31aad9b9b22e46d99a270ed5aebb259fab64dcc"
},
{
"ImportPath": "github.com/jbenet/go-is-domain",
......
{
"ImportPath": "github.com/jbenet/go-datastore",
"GoVersion": "go1.3.1",
"GoVersion": "go1.3.3",
"Packages": [
"./..."
],
......@@ -33,11 +33,16 @@
},
{
"ImportPath": "github.com/syndtr/goleveldb/leveldb",
"Rev": "9bca75c48d6c31becfbb127702b425e7226052e3"
"Rev": "cd2b8f743192883ab9fbc5f070ebda1dc90f3732"
},
{
"ImportPath": "gopkg.in/check.v1",
"Rev": "91ae5f88a67b14891cfd43895b01164f6c120420"
},
{
"ImportPath": "launchpad.net/gocheck",
"Comment": "87",
"Rev": "gustavo@niemeyer.net-20140225173054-xu9zlkf9kxhvow02"
}
]
}
build:
go build
# saves/vendors third-party dependencies to Godeps/_workspace
# -r flag rewrites import paths to use the vendored path
# ./... performs operation on all packages in tree
vendor: godep
godep save -r ./...
deps:
go get ./...
......@@ -10,3 +16,6 @@ watch:
# for portability, use watchmedo -- pip install watchmedo
@watchmedo shell-command --patterns="*.go;" --recursive \
--command='make' .
godep:
go get github.com/tools/godep
......@@ -2,7 +2,6 @@ package fs_test
import (
"bytes"
"sort"
"testing"
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
......@@ -13,7 +12,10 @@ import (
// Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { TestingT(t) }
type DSSuite struct{}
type DSSuite struct {
dir string
ds ds.Datastore
}
var _ = Suite(&DSSuite{})
......@@ -52,22 +54,6 @@ func (ks *DSSuite) TestBasic(c *C) {
c.Check(err, Equals, nil)
c.Check(bytes.Equal(v.([]byte), []byte(k.String())), Equals, true)
}
listA, errA := mpds.KeyList()
listB, errB := ktds.KeyList()
c.Check(errA, Equals, nil)
c.Check(errB, Equals, nil)
c.Check(len(listA), Equals, len(listB))
// sort them cause yeah.
sort.Sort(ds.KeySlice(listA))
sort.Sort(ds.KeySlice(listB))
for i, kA := range listA {
kB := listB[i]
c.Check(pair.Invert(kA), Equals, kB)
c.Check(kA, Equals, pair.Convert(kB))
}
}
func strsToKeys(strs []string) []ds.Key {
......
package leveldb
import (
"io"
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt"
)
// Datastore uses a standard Go map for internal storage.
type Datastore struct {
type Datastore interface {
ds.ThreadSafeDatastore
io.Closer
}
type datastore struct {
DB *leveldb.DB
}
type Options opt.Options
func NewDatastore(path string, opts *Options) (ds.ThreadSafeDatastore, error) {
func NewDatastore(path string, opts *Options) (Datastore, error) {
var nopts opt.Options
if opts != nil {
nopts = opt.Options(*opts)
......@@ -23,7 +29,7 @@ func NewDatastore(path string, opts *Options) (ds.ThreadSafeDatastore, error) {
return nil, err
}
return &Datastore{
return &datastore{
DB: db,
}, nil
}
......@@ -32,7 +38,7 @@ func NewDatastore(path string, opts *Options) (ds.ThreadSafeDatastore, error) {
//
// Note: using sync = false.
// see http://godoc.org/github.com/syndtr/goleveldb/leveldb/opt#WriteOptions
func (d *Datastore) Put(key ds.Key, value interface{}) (err error) {
func (d *datastore) Put(key ds.Key, value interface{}) (err error) {
val, ok := value.([]byte)
if !ok {
return ds.ErrInvalidType
......@@ -40,7 +46,7 @@ func (d *Datastore) Put(key ds.Key, value interface{}) (err error) {
return d.DB.Put(key.Bytes(), val, nil)
}
func (d *Datastore) Get(key ds.Key) (value interface{}, err error) {
func (d *datastore) Get(key ds.Key) (value interface{}, err error) {
val, err := d.DB.Get(key.Bytes(), nil)
if err != nil {
if err == leveldb.ErrNotFound {
......@@ -51,11 +57,11 @@ func (d *Datastore) Get(key ds.Key) (value interface{}, err error) {
return val, nil
}
func (d *Datastore) Has(key ds.Key) (exists bool, err error) {
func (d *datastore) Has(key ds.Key) (exists bool, err error) {
return ds.GetBackedHas(d, key)
}
func (d *Datastore) Delete(key ds.Key) (err error) {
func (d *datastore) Delete(key ds.Key) (err error) {
err = d.DB.Delete(key.Bytes(), nil)
if err == leveldb.ErrNotFound {
return ds.ErrNotFound
......@@ -63,18 +69,18 @@ func (d *Datastore) Delete(key ds.Key) (err error) {
return err
}
func (d *Datastore) KeyList() ([]ds.Key, error) {
func (d *datastore) KeyList() ([]ds.Key, error) {
i := d.DB.NewIterator(nil, nil)
var keys []ds.Key
for ; i.Valid(); i.Next() {
for i.Next() {
keys = append(keys, ds.NewKey(string(i.Key())))
}
return keys, nil
}
// LevelDB needs to be closed.
func (d *Datastore) Close() (err error) {
func (d *datastore) Close() (err error) {
return d.DB.Close()
}
func (d *Datastore) IsThreadSafe() {}
func (d *datastore) IsThreadSafe() {}
......@@ -24,7 +24,7 @@ func Example() {
v3, _ := mp.Get(k3)
fmt.Printf("mp.Get %s -> %s\n", k3, v3)
// Output:
// ns.Put /beep -> boop
// ns.Put /beep boop
// ns.Get /beep -> boop
// mp.Get /foo/bar/beep -> boop
}
package datastore
// type KeyIterator struct {
// HasNext() bool
// Next() interface{}
// }
// type Query struct {
// }
/*
QueryDatastores support a Query interface. Queries are used to support
searching for values (beyond simple key-based `Get`s).
*/
// type QueryDatastore interface {
// // Query returns an Iterator of Keys whose Values match criteria
// // expressed in `query`.
// Query(Query) (iter Iterator, err error)
// }
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