浏览代码

Ensure the parent directory for key prefix exists

Currently we are trying to ensure that the parent
directory exists as a key. But it is really a directory
and etcd expects it to be a directory. So made the
change to ensure that the parent key is created as
a directory and not as a simple key.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
Jana Radhakrishnan 9 年之前
父节点
当前提交
72b8f80dc3
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      libnetwork/datastore/datastore.go

+ 4 - 4
libnetwork/datastore/datastore.go

@@ -385,15 +385,15 @@ func (ds *datastore) GetObject(key string, o KVObject) error {
 	return nil
 }
 
-func (ds *datastore) ensureKey(key string) error {
-	exists, err := ds.store.Exists(key)
+func (ds *datastore) ensureParent(parent string) error {
+	exists, err := ds.store.Exists(parent)
 	if err != nil {
 		return err
 	}
 	if exists {
 		return nil
 	}
-	return ds.store.Put(key, []byte{}, nil)
+	return ds.store.Put(parent, []byte{}, &store.WriteOptions{IsDir: true})
 }
 
 func (ds *datastore) List(key string, kvObject KVObject) ([]KVObject, error) {
@@ -411,7 +411,7 @@ func (ds *datastore) List(key string, kvObject KVObject) ([]KVObject, error) {
 	}
 
 	// Make sure the parent key exists
-	if err := ds.ensureKey(key); err != nil {
+	if err := ds.ensureParent(key); err != nil {
 		return nil, err
 	}