Browse Source

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 <madhu@docker.com>
Madhu Venugopal 10 years ago
parent
commit
e2fea0f945
2 changed files with 12 additions and 8 deletions
  1. 10 8
      libnetwork/endpoint.go
  2. 2 0
      libnetwork/libnetwork_test.go

+ 10 - 8
libnetwork/endpoint.go

@@ -526,21 +526,23 @@ func (ep *endpoint) updateDNS(resolvConf []byte) error {
 		return ErrNoContainer
 		return ErrNoContainer
 	}
 	}
 
 
+	oldHash := []byte{}
 	hashFile := container.config.resolvConfPath + ".hash"
 	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)
 	resolvBytes, err := ioutil.ReadFile(container.config.resolvConfPath)
 	if err != nil {
 	if err != nil {
 		if !os.IsNotExist(err) {
 		if !os.IsNotExist(err) {
 			return 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))
 	curHash, err := ioutils.HashData(bytes.NewReader(resolvBytes))

+ 2 - 0
libnetwork/libnetwork_test.go

@@ -995,6 +995,7 @@ func TestEnableIPv6(t *testing.T) {
 	}
 	}
 
 
 	resolvConfPath := "/tmp/libnetwork_test/resolv.conf"
 	resolvConfPath := "/tmp/libnetwork_test/resolv.conf"
+	defer os.Remove(resolvConfPath)
 
 
 	_, err = ep1.Join(containerID,
 	_, err = ep1.Join(containerID,
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))
@@ -1061,6 +1062,7 @@ func TestResolvConf(t *testing.T) {
 	}
 	}
 
 
 	resolvConfPath := "/tmp/libnetwork_test/resolv.conf"
 	resolvConfPath := "/tmp/libnetwork_test/resolv.conf"
+	defer os.Remove(resolvConfPath)
 
 
 	_, err = ep1.Join(containerID,
 	_, err = ep1.Join(containerID,
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))
 		libnetwork.JoinOptionResolvConfPath(resolvConfPath))