Skip to content

Commit

Permalink
Requested changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnavarro committed Dec 6, 2022
1 parent cc967e9 commit 35efa59
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var swarmPeeringAddCmd = &cmds.Command{
save, _ := req.Options[swarmSaveOptionName].(bool)
if save {
update := func(cfg *config.Config) {
cfg.Peering.Peers = node.Peering.ListPeers()
cfg.Peering.Peers = append(cfg.Peering.Peers, addInfos...)
}
err := updateAndPersistConfig(env, update)
if err != nil {
Expand Down Expand Up @@ -231,16 +231,25 @@ var swarmPeeringRmCmd = &cmds.Command{
if err = res.Emit(peeringResult{id, "success"}); err != nil {
return err
}
}

save, _ := req.Options[swarmSaveOptionName].(bool)
if save {
update := func(cfg *config.Config) {
cfg.Peering.Peers = node.Peering.ListPeers()
}
err := updateAndPersistConfig(env, update)
if err != nil {
return fmt.Errorf("unable to update and persist config change: %w", err)
save, _ := req.Options[swarmSaveOptionName].(bool)
if save {
update := func(cfg *config.Config) {
var cfgOut []peer.AddrInfo
for _, p := range cfg.Peering.Peers {
if p.ID == id {
continue
}
cfgOut = append(cfgOut, p)
}

cfg.Peering.Peers = cfgOut
}

err := updateAndPersistConfig(env, update)
if err != nil {
return fmt.Errorf("unable to update and persist config change: %w", err)
}
}
}

Expand Down

0 comments on commit 35efa59

Please sign in to comment.