From 2c4396e42ad56438dc086afa1da1658275d66289 Mon Sep 17 00:00:00 2001 From: b5 Date: Wed, 12 Dec 2018 14:37:31 -0500 Subject: [PATCH] fix(config migrate): fix crash in migration this is why tests are a good idea --- config/migrate/migrate.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/config/migrate/migrate.go b/config/migrate/migrate.go index b194d6d31..04e20ab4c 100644 --- a/config/migrate/migrate.go +++ b/config/migrate/migrate.go @@ -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 @@ -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) } } } @@ -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] +}