From b0c130c5b382a75c2e78d1dc674b4b889ef1b35f Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Tue, 28 Jul 2015 08:46:08 +0100
Subject: [PATCH] use CreateDir to initialize presence directory

---
 coordination/etcdtest/fake_etcd.go | 2 +-
 coordination/presence/presence.go  | 9 +++------
 etcd_client.go                     | 2 +-
 3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/coordination/etcdtest/fake_etcd.go b/coordination/etcdtest/fake_etcd.go
index b82eca0c..6cf02c28 100644
--- a/coordination/etcdtest/fake_etcd.go
+++ b/coordination/etcdtest/fake_etcd.go
@@ -200,7 +200,7 @@ func (s *FakeEtcdClient) Set(key, value string, ttl uint64) (*etcd.Response, err
 	return s.trigger("set", key), nil
 }
 
-func (s *FakeEtcdClient) SetDir(key string, ttl uint64) (*etcd.Response, error) {
+func (s *FakeEtcdClient) CreateDir(key string, ttl uint64) (*etcd.Response, error) {
 	// TODO. There are no directories.
 	return &etcd.Response{}, nil
 }
diff --git a/coordination/presence/presence.go b/coordination/presence/presence.go
index 7c11c5b1..41c95864 100644
--- a/coordination/presence/presence.go
+++ b/coordination/presence/presence.go
@@ -1,7 +1,6 @@
 package presence
 
 import (
-	"fmt"
 	"log"
 	"time"
 
@@ -12,10 +11,10 @@ import (
 type EtcdClient interface {
 	AddChild(key string, value string, ttl uint64) (*etcd.Response, error)
 	Create(key string, value string, ttl uint64) (*etcd.Response, error)
+	CreateDir(key string, ttl uint64) (*etcd.Response, error)
 	Update(key string, value string, ttl uint64) (*etcd.Response, error)
 	Delete(key string, recursive bool) (*etcd.Response, error)
 	Get(key string, sort, recursive bool) (*etcd.Response, error)
-	SetDir(key string, ttl uint64) (*etcd.Response, error)
 }
 
 // A Client can read the list of active nodes written by Presence workers.
@@ -77,10 +76,8 @@ func (p *Presence) Stop() {
 
 // Start the presence worker.
 func (p *Presence) Start() error {
-	// Create the presence directory if it does not exist.
-	if _, err := p.client.SetDir(p.path, 0); err != nil {
-		return fmt.Errorf("could not create presence directory: %v", err)
-	}
+	// Create the presence directory if it does not exist. Ignore errors.
+	p.client.CreateDir(p.path, 0)
 
 	go p.run()
 	return nil
diff --git a/etcd_client.go b/etcd_client.go
index 51208436..ab18aa3d 100644
--- a/etcd_client.go
+++ b/etcd_client.go
@@ -90,11 +90,11 @@ func NewEtcdClient(strongReads bool) EtcdClient {
 type EtcdClient interface {
 	AddChild(string, string, uint64) (*etcd.Response, error)
 	Create(string, string, uint64) (*etcd.Response, error)
+	CreateDir(string, uint64) (*etcd.Response, error)
 	CompareAndSwap(string, string, uint64, string, uint64) (*etcd.Response, error)
 	Delete(string, bool) (*etcd.Response, error)
 	Get(string, bool, bool) (*etcd.Response, error)
 	Set(string, string, uint64) (*etcd.Response, error)
-	SetDir(string, uint64) (*etcd.Response, error)
 	Update(string, string, uint64) (*etcd.Response, error)
 	Watch(string, uint64, bool, chan *etcd.Response, chan bool) (*etcd.Response, error)
 }
-- 
GitLab