Skip to content

Commit

Permalink
client: Deep Copy HostVolumeConfig map
Browse files Browse the repository at this point in the history
  • Loading branch information
endocrimes committed Jul 25, 2019
1 parent 56a53d6 commit 5935e7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func (c *Config) Copy() *Config {
nc.Node = nc.Node.Copy()
nc.Servers = helper.CopySliceString(nc.Servers)
nc.Options = helper.CopyMapStringString(nc.Options)
nc.HostVolumes = structs.CopyMapStringClientHostVolumeConfig(nc.HostVolumes)
nc.ConsulConfig = c.ConsulConfig.Copy()
nc.VaultConfig = c.VaultConfig.Copy()
return nc
Expand Down
13 changes: 13 additions & 0 deletions nomad/structs/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ func (p *ClientHostVolumeConfig) Copy() *ClientHostVolumeConfig {
return c
}

func CopyMapStringClientHostVolumeConfig(m map[string]*ClientHostVolumeConfig) map[string]*ClientHostVolumeConfig {
if m == nil {
return nil
}

nm := make(map[string]*ClientHostVolumeConfig, len(m))
for k, v := range m {
nm[k] = v.Copy()
}

return nm
}

func HostVolumeSliceMerge(a, b []*ClientHostVolumeConfig) []*ClientHostVolumeConfig {
n := make([]*ClientHostVolumeConfig, len(a))
seenKeys := make(map[string]struct{}, len(a))
Expand Down

0 comments on commit 5935e7a

Please sign in to comment.