From e2fea0f9455268bbc4b379f53c2dfaff9c33300b Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Sat, 16 May 2015 05:13:17 -0700 Subject: [PATCH] Ignore the OldHash if the resolvConfPath is invalid If resolvConfPath is unavailable and if the internally generated .hash file is still present, then updateDNS should not consider the presence of internally generated .hash. Rather, it must handle it as a case of using this resolvConfPath for the first time. Signed-off-by: Madhu Venugopal --- libnetwork/endpoint.go | 18 ++++++++++-------- libnetwork/libnetwork_test.go | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libnetwork/endpoint.go b/libnetwork/endpoint.go index 702193da24..6be7fe6ad7 100644 --- a/libnetwork/endpoint.go +++ b/libnetwork/endpoint.go @@ -526,21 +526,23 @@ func (ep *endpoint) updateDNS(resolvConf []byte) error { return ErrNoContainer } + oldHash := []byte{} hashFile := container.config.resolvConfPath + ".hash" - oldHash, err := ioutil.ReadFile(hashFile) - if err != nil { - if !os.IsNotExist(err) { - return err - } - - oldHash = []byte{} - } resolvBytes, err := ioutil.ReadFile(container.config.resolvConfPath) if err != nil { if !os.IsNotExist(err) { return err } + } else { + oldHash, err = ioutil.ReadFile(hashFile) + if err != nil { + if !os.IsNotExist(err) { + return err + } + + oldHash = []byte{} + } } curHash, err := ioutils.HashData(bytes.NewReader(resolvBytes)) diff --git a/libnetwork/libnetwork_test.go b/libnetwork/libnetwork_test.go index 2a020ada37..d15d20030f 100644 --- a/libnetwork/libnetwork_test.go +++ b/libnetwork/libnetwork_test.go @@ -995,6 +995,7 @@ func TestEnableIPv6(t *testing.T) { } resolvConfPath := "/tmp/libnetwork_test/resolv.conf" + defer os.Remove(resolvConfPath) _, err = ep1.Join(containerID, libnetwork.JoinOptionResolvConfPath(resolvConfPath)) @@ -1061,6 +1062,7 @@ func TestResolvConf(t *testing.T) { } resolvConfPath := "/tmp/libnetwork_test/resolv.conf" + defer os.Remove(resolvConfPath) _, err = ep1.Join(containerID, libnetwork.JoinOptionResolvConfPath(resolvConfPath))