github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/image/cache/compare.go (about)

     1  package cache // import "github.com/demonoid81/moby/image/cache"
     2  
     3  import (
     4  	"github.com/demonoid81/moby/api/types/container"
     5  )
     6  
     7  // compare two Config struct. Do not compare the "Image" nor "Hostname" fields
     8  // If OpenStdin is set, then it differs
     9  func compare(a, b *container.Config) bool {
    10  	if a == nil || b == nil ||
    11  		a.OpenStdin || b.OpenStdin {
    12  		return false
    13  	}
    14  	if a.AttachStdout != b.AttachStdout ||
    15  		a.AttachStderr != b.AttachStderr ||
    16  		a.User != b.User ||
    17  		a.OpenStdin != b.OpenStdin ||
    18  		a.Tty != b.Tty {
    19  		return false
    20  	}
    21  
    22  	if len(a.Cmd) != len(b.Cmd) ||
    23  		len(a.Env) != len(b.Env) ||
    24  		len(a.Labels) != len(b.Labels) ||
    25  		len(a.ExposedPorts) != len(b.ExposedPorts) ||
    26  		len(a.Entrypoint) != len(b.Entrypoint) ||
    27  		len(a.Volumes) != len(b.Volumes) {
    28  		return false
    29  	}
    30  
    31  	for i := 0; i < len(a.Cmd); i++ {
    32  		if a.Cmd[i] != b.Cmd[i] {
    33  			return false
    34  		}
    35  	}
    36  	for i := 0; i < len(a.Env); i++ {
    37  		if a.Env[i] != b.Env[i] {
    38  			return false
    39  		}
    40  	}
    41  	for k, v := range a.Labels {
    42  		if v != b.Labels[k] {
    43  			return false
    44  		}
    45  	}
    46  	for k := range a.ExposedPorts {
    47  		if _, exists := b.ExposedPorts[k]; !exists {
    48  			return false
    49  		}
    50  	}
    51  
    52  	for i := 0; i < len(a.Entrypoint); i++ {
    53  		if a.Entrypoint[i] != b.Entrypoint[i] {
    54  			return false
    55  		}
    56  	}
    57  	for key := range a.Volumes {
    58  		if _, exists := b.Volumes[key]; !exists {
    59  			return false
    60  		}
    61  	}
    62  	return true
    63  }