runconfig/compare.go
6393c383
 package runconfig
 
907407d0
 import "github.com/docker/engine-api/types/container"
7ac4232e
 
6393c383
 // Compare two Config struct. Do not compare the "Image" nor "Hostname" fields
 // If OpenStdin is set, then it differs
7ac4232e
 func Compare(a, b *container.Config) bool {
6393c383
 	if a == nil || b == nil ||
 		a.OpenStdin || b.OpenStdin {
 		return false
 	}
 	if a.AttachStdout != b.AttachStdout ||
 		a.AttachStderr != b.AttachStderr ||
 		a.User != b.User ||
 		a.OpenStdin != b.OpenStdin ||
af974641
 		a.Tty != b.Tty {
6393c383
 		return false
 	}
767df67e
 
 	if a.Cmd.Len() != b.Cmd.Len() ||
6393c383
 		len(a.Env) != len(b.Env) ||
b4beb063
 		len(a.Labels) != len(b.Labels) ||
6393c383
 		len(a.ExposedPorts) != len(b.ExposedPorts) ||
767df67e
 		a.Entrypoint.Len() != b.Entrypoint.Len() ||
6393c383
 		len(a.Volumes) != len(b.Volumes) {
 		return false
 	}
 
767df67e
 	aCmd := a.Cmd.Slice()
 	bCmd := b.Cmd.Slice()
 	for i := 0; i < len(aCmd); i++ {
 		if aCmd[i] != bCmd[i] {
6393c383
 			return false
 		}
 	}
 	for i := 0; i < len(a.Env); i++ {
 		if a.Env[i] != b.Env[i] {
 			return false
 		}
 	}
b4beb063
 	for k, v := range a.Labels {
 		if v != b.Labels[k] {
 			return false
 		}
 	}
6393c383
 	for k := range a.ExposedPorts {
 		if _, exists := b.ExposedPorts[k]; !exists {
 			return false
 		}
 	}
767df67e
 
 	aEntrypoint := a.Entrypoint.Slice()
 	bEntrypoint := b.Entrypoint.Slice()
 	for i := 0; i < len(aEntrypoint); i++ {
 		if aEntrypoint[i] != bEntrypoint[i] {
6393c383
 			return false
 		}
 	}
 	for key := range a.Volumes {
 		if _, exists := b.Volumes[key]; !exists {
 			return false
 		}
 	}
 	return true
 }