Skip to content

Commit

Permalink
fix(config migrate): fix crash in migration
Browse files Browse the repository at this point in the history
this is why tests are a good idea
  • Loading branch information
b5 committed Dec 12, 2018
1 parent 3ea2244 commit 2c4396e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions config/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func RunMigrations(streams ioes.IOStreams, cfg *config.Config) (migrated bool, e
if err := ZeroToOne(cfg); err != nil {
return false, err
}
streams.Print("done!")
streams.Print("done!\n")
return true, nil
}
return false, nil
Expand All @@ -34,12 +34,13 @@ func ZeroToOne(cfg *config.Config) error {
for i, addr := range cfg.P2P.QriBootstrapAddrs {
// remove any old, invalid addresses
if removes[addr] {
cfg.P2P.QriBootstrapAddrs = append(cfg.P2P.QriBootstrapAddrs[:i], cfg.P2P.QriBootstrapAddrs[i+1:]...)
cfg.P2P.QriBootstrapAddrs = delIdx(i, cfg.P2P.QriBootstrapAddrs)
}
// remove address from list of additions if already configured
for j, add := range adds {
if addr == add {
adds = append(adds[:j], adds[j+1:]...)
// adds = append(adds[:j], adds[j+1:]...)
adds = delIdx(j, adds)
}
}
}
Expand All @@ -50,3 +51,11 @@ func ZeroToOne(cfg *config.Config) error {
cfg.Revision = 1
return nil
}

func delIdx(i int, sl []string) []string {
if i < len(sl)-1 {
return append(sl[:i], sl[i+1:]...)
}

return sl[:i]
}

0 comments on commit 2c4396e

Please sign in to comment.