瀏覽代碼

libnetwork/datastore: don't parse file path

File paths can contain commas, particularly paths returned from
t.TempDir() in subtests which include commas in their names. There is
only one datastore provider and it only supports a single address, so
the only use of parsing the address is to break tests in mysterious
ways.

Signed-off-by: Cory Snider <csnider@mirantis.com>
Cory Snider 1 年之前
父節點
當前提交
2200c0137f
共有 2 個文件被更改,包括 5 次插入13 次删除
  1. 1 2
      libnetwork/datastore/datastore.go
  2. 4 11
      libnetwork/internal/kvstore/boltdb/boltdb.go

+ 1 - 2
libnetwork/datastore/datastore.go

@@ -129,8 +129,7 @@ func newClient(kv string, addr string, config *store.Config) (*Store, error) {
 		config = &store.Config{}
 		config = &store.Config{}
 	}
 	}
 
 
-	// Parse file path
-	s, err := boltdb.New(strings.Split(addr, ","), config)
+	s, err := boltdb.New(addr, config)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}

+ 4 - 11
libnetwork/internal/kvstore/boltdb/boltdb.go

@@ -15,9 +15,6 @@ import (
 )
 )
 
 
 var (
 var (
-	// ErrMultipleEndpointsUnsupported is thrown when multiple endpoints specified for
-	// BoltDB. Endpoint has to be a local file path
-	ErrMultipleEndpointsUnsupported = errors.New("boltdb supports one endpoint and should be a file path")
 	// ErrBoltBucketOptionMissing is thrown when boltBcuket config option is missing
 	// ErrBoltBucketOptionMissing is thrown when boltBcuket config option is missing
 	ErrBoltBucketOptionMissing = errors.New("boltBucket config option missing")
 	ErrBoltBucketOptionMissing = errors.New("boltBucket config option missing")
 )
 )
@@ -46,16 +43,12 @@ const (
 )
 )
 
 
 // New opens a new BoltDB connection to the specified path and bucket
 // New opens a new BoltDB connection to the specified path and bucket
-func New(endpoints []string, options *store.Config) (store.Store, error) {
-	if len(endpoints) > 1 {
-		return nil, ErrMultipleEndpointsUnsupported
-	}
-
+func New(endpoint string, options *store.Config) (store.Store, error) {
 	if (options == nil) || (len(options.Bucket) == 0) {
 	if (options == nil) || (len(options.Bucket) == 0) {
 		return nil, ErrBoltBucketOptionMissing
 		return nil, ErrBoltBucketOptionMissing
 	}
 	}
 
 
-	dir, _ := filepath.Split(endpoints[0])
+	dir, _ := filepath.Split(endpoint)
 	if err := os.MkdirAll(dir, 0o750); err != nil {
 	if err := os.MkdirAll(dir, 0o750); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -63,7 +56,7 @@ func New(endpoints []string, options *store.Config) (store.Store, error) {
 	var db *bolt.DB
 	var db *bolt.DB
 	if options.PersistConnection {
 	if options.PersistConnection {
 		var err error
 		var err error
-		db, err = bolt.Open(endpoints[0], filePerm, &bolt.Options{
+		db, err = bolt.Open(endpoint, filePerm, &bolt.Options{
 			Timeout: options.ConnectionTimeout,
 			Timeout: options.ConnectionTimeout,
 		})
 		})
 		if err != nil {
 		if err != nil {
@@ -78,7 +71,7 @@ func New(endpoints []string, options *store.Config) (store.Store, error) {
 
 
 	b := &BoltDB{
 	b := &BoltDB{
 		client:            db,
 		client:            db,
-		path:              endpoints[0],
+		path:              endpoint,
 		boltBucket:        []byte(options.Bucket),
 		boltBucket:        []byte(options.Bucket),
 		timeout:           timeout,
 		timeout:           timeout,
 		PersistConnection: options.PersistConnection,
 		PersistConnection: options.PersistConnection,